Tag: wpf

无法引用包含合并字典的资源字典

我有一个库,CommonLibraryWpfThemes,里面有几个Resource Dictionary XAML文件。 我的主题/ Generic.xml文件包含将所有其他文件合并在一起的ResourceDictionary.MergedDictionaries声明。 Generic.xaml <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="/CommonLibraryWpfThemes;component/ResourceDictionaries/BrushDictionary.xaml" /> <ResourceDictionary Source="/CommonLibraryWpfThemes;component/ResourceDictionaries/TextBlockDictionary.xaml" /> <ResourceDictionary Source="/CommonLibraryWpfThemes;component/ResourceDictionaries/LabelDictionary.xaml" /> <ResourceDictionary Source="/CommonLibraryWpfThemes;component/ResourceDictionaries/ButtonDictionary.xaml" /> <ResourceDictionary Source="/CommonLibraryWpfThemes;component/ResourceDictionaries/WindowDictionary.xaml" /> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> 在我的应用程序项目中,我引用了CommonLibraryWpfThemes,并且在App.xaml文件中明确引用了Generic.xml。 App.xaml – 失败 <Application x:Class="MyApp.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <Application.Resources> <ResourceDictionary Source="/CommonLibraryWpfThemes;component/Themes/Generic.xaml" /> </Application.Resources> </Application> 这不起作用。 我运行我的应用程序时出现以下错误: System.Windows.Markup.XamlParseException occurred Message="Cannot find resource named '{_fadedOrangeBrush}'. Resource names are case sensitive. […]

ScrollViewer鼠标滚轮不工作

我目前正在做我的第一个WPF项目,并试图做一个ListView滚动。 起初,我认为这可以很容易地通过简单地限制列表视图的宽度和高度,从而迫使一个滚动条自动出现,每当内容超过其空间。 这看起来很好,但由于处理PreviewMouseDown事件(这使拖动列表的项目)select一个项目后,它不起作用。 第二次尝试 (使用ScrollViewer) <ScrollViewer> <ListView ItemsSource="{Binding FileViewModels}" PreviewMouseDown="ListView_MouseMove" Height="450" Width="200"/> </ScrollViewer> 当然,当列表的内容变得大于最大高度时,这会导致第二个滚动条。 select一个项目后,拖动栏仍然不起作用。 第三 (相当愚蠢的) 尝试 (禁用滚动条复制) <ScrollViewer> <ListView ItemsSource="{Binding FileViewModels}" PreviewMouseDown="ListView_MouseMove" Height="450" Width="200" ScrollViewer.VerticalScrollBarVisibility="Disabled" ScrollViewer.HorizontalScrollBarVisibility="Disabled"/> </ScrollViewer> 这删除了滚动条复制,并通过鼠标滚轮启用滚动,但禁用滚动条,所以你不能通过点击和拖动它。 第四次尝试 (ScrollViewer的大小不变) <ScrollViewer Height="450" Width="200"> <ListView ItemsSource="{Binding FileViewModels}" PreviewMouseDown="ListView_MouseMove"/> </ScrollViewer> 从ListView中移除宽度/高度约束并将其移至ScrollViewer。 这使滚动条和删除重复。 不幸的是,鼠标滚轮不再工作(拖动滚动条工作正常)。 请问有人请向我解释为什么鼠标滚轮不再工作,以及如何解决这个问题? 编辑也许我应该回到我的第一个解决scheme。 显然,ListView的模板已经包含了一个ScrollViewer。 剩下的问题就是因为处理过的PreviewMouseDown事件(在这种情况下通过鼠标滚动仍然有效)select一个项目后,我不能拖动滚动条。 我是否应该以不同的方式处理项目的拖动(在我想添加滚动条之前,它可以正常工作)? 或者有没有办法来检测光标是否在滚动条上方(这样我可以取消select启用滚动的项目)? 或者还有其他build议吗?

样式和ControlTemplate之间的区别

你能告诉我Style和ControlTemplate之间的主要区别是什么? 何时或为什么要使用其中一个? 在我看来,他们是完全一样的 。 因为我是初学者,我认为我错了,所以我的问题。

减lessTextBlock / FlowDocument中的行间距

一些字体在字符上方和下方都有大量的空白。 有没有一种方法来纠正这个问题,并加紧WPF中的一个单词包装的段落(在TextBlock或FlowDocument)的行之间的空间? 有点像线之间的负边距? 在Paragraph和TextBlock上有一个LineHeight属性,但它似乎只是让你增加间距 – 如果你设置的值比默认值小,那么它就被忽略了。

什么是每个WPF文件中的xmlns?

什么是xmlns ? 在创buildWPF项目时,它在XAML文件中起什么作用?

从ListView冒泡滚动事件到其父

在我的WPF应用程序中,我有一个ListView其ScrollViewer.VerticalScrollBarVisibility被设置为Disabled 。 它包含在ScrollViewer 。 当我尝试在ListView上使用鼠标滚轮时,外部ScrollViewer不滚动,因为ListView正在捕获滚动事件。 我如何强制ListView允许滚动事件向上ScrollViewer到ScrollViewer ?

WPF学习曲线有多糟糕?

我已经从几个人那里听说过, WPF的学习曲线非常陡峭(取决于你的知识或经验)。 看起来像大多数人可以让演示或启动项目工作,然后发现自己被困在一些杂项问题的时间长度。 我很好奇什么是特别难以学习或理解(图层,SDK, XAML ,数据绑定等),如果您有任何build议如何避免/减轻一些这些困难的话题?

将参数添加到button单击事件

我有一个像这样的wpfbutton: <Button Click="button1_Click" Height="23" Margin="0,0,5,0" Name="button1" Width="75">Initiate</Button> 我想传递{Binding Code}作为parameter passing给button1_click处理程序。 我如何去做这件事? 免责声明:对WPF来说真的很新鲜

我怎样才能连接xaml和xaml.cs文件

我有一个VB投影,并使用在线转换工具将其转换为C#。 现在问题是xaml和xaml.cs文件不能相互连接,也就是说他们不能识别它们的依赖关系(图中的红色区域)。 实际上,它应该像Window1文件(图像中的绿色区域)。我怎样才能实现这一点。 我正在尝试使用WPF,所以可能是一个普通人的问题。

在XAML中绑定到Self /'this'

简单的WPF / XAML问题。 在XAML中,如何在给定的上下文中引用Self / this对象? 在一个非常基本的应用程序中,窗口的主窗口,一个控件和一个编码的C#属性,我想将控件的属性绑定到窗口的手工编码属性。 在代码中,这很容易 – 在Window的构造函数中,我添加了这个: Binding bind = new Binding(); bind.Source = this; bind.Path = new PropertyPath("ButtonWidth"); button1.SetBinding(WidthProperty, bind); 很明显,我有一个名为ButtonWidth的属性,以及一个名为button1的控件。 我无法弄清楚如何在XAML中做到这一点。 像下面的例子的各种尝试没有奏效: <Button x:Name="button1" Width="{Binding Source=Self Path=ButtonWidth}"/> <Button x:Name="button1" Width="{Binding RelativeSource={RelativeSource Self} Path=ButtonWidth}"/> 等等 谢谢