WPF控件包括UserControls,它是其他控件的复合集合,以及CustomControls,它们是使用WPF样式和模板构建的控件。
我相信微软最近发布了WPF的源代码。我知道已经有.Net库的源代码参考(Source Reference) 我看到微软 WPF 控件的源代码...
我想创建一个具有多个 WPF 依赖属性的自定义控件。 属性之一是返回 Thickness 对象。 自定义控件应该适合设计使用...
我想制作一个自定义控件标签,它可以有一个名为百分比的属性,背景将根据该百分比填充。示例:label.Percentage = 70 然后
我正在编写一个 WPF 应用程序来进行意大利语词汇练习。 当我尝试使用 Windows 键盘快捷键输入重音字符时,它仅作为基础字符出现在文本框中。 例如...
我在 WPF StackPanel 和 WrapPanel 中放置了一些标签,如下所示,这样我就可以用粗体显示其中的部分内容。 我在 WPF StackPanel 和 WrapPanel 中放置了一些标签,如下所示,这样我就可以用粗体显示其中的部分内容。 <Grid Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="1" Grid.RowSpan="2"> <StackPanel Margin="10,15,20,5" > <WrapPanel Orientation="Horizontal" HorizontalAlignment="Center"> <Label Name="WarningLabelTextLookOverPart1" Content="{Binding WarningLabelTextLookOverPart1}" FontFamily="{DynamicResource NormalFontFamily}" FontSize="{DynamicResource NormalFontSize}" FontWeight="Normal" Style="{DynamicResource H2Label}" Foreground="{DynamicResource BlackEightyBrush}" Visibility="{Binding ShowIdCapture, Converter={StaticResource BooleanVisibilityConverterCollapsedWhenFalse}}"/> <Label Name="WarningLabelTextLookOverPart2" Content="{Binding WarningLabelTextLookOverPart2}" FontFamily="{DynamicResource NormalFontFamily}" FontSize="{DynamicResource NormalFontSize}" FontWeight="Bold" Style="{DynamicResource H2Label}" Foreground="{DynamicResource BlackEightyBrush}" Visibility="{Binding ShowIdCapture, Converter={StaticResource BooleanVisibilityConverterCollapsedWhenFalse}}"/> <Label Name="WarningLabelTextLookOverPart3" Content="{Binding WarningLabelTextLookOverPart3}" FontFamily="{DynamicResource NormalFontFamily}" FontSize="{DynamicResource NormalFontSize}" FontWeight="Normal" Style="{DynamicResource H2Label}" Foreground="{DynamicResource BlackEightyBrush}" Visibility="{Binding ShowIdCapture, Converter={StaticResource BooleanVisibilityConverterCollapsedWhenFalse}}"/> <Label Name="WarningLabelTextLookOverPart4" Content="{Binding WarningLabelTextLookOverPart4}" FontFamily="{DynamicResource NormalFontFamily}" FontSize="{DynamicResource NormalFontSize}" FontWeight="Bold" Style="{DynamicResource H2Label}" Foreground="{DynamicResource BlackEightyBrush}" Visibility="{Binding ShowIdCapture, Converter={StaticResource BooleanVisibilityConverterCollapsedWhenFalse}}"/> </WrapPanel> </StackPanel> </Grid> 看起来像这样 有关如何将标签集中对齐的任何建议,即将“您被起诉”部分居中。 您可以将 UniformGrid 与 1 列与 WrapPanel 组合使用,如下所示 <Grid Grid.Row="1" Grid.RowSpan="2" Grid.Column="0" Grid.ColumnSpan="2"> <StackPanel Margin="10,15,20,5"> <UniformGrid HorizontalAlignment="Center" Columns="1"> <WrapPanel Orientation="Horizontal"> <Label Name="WarningLabelTextLookOverPart1" Content="If the customer look under 25," FontWeight="Normal" Foreground="Black"/> <Label Name="WarningLabelTextLookOverPart2" Content="it's YOUR reposibility to ask for ID" FontWeight="Bold" Foreground="Black"/> <Label Name="WarningLabelTextLookOverPart3" Content="to check this and failure to do so could result in" FontWeight="Normal" Foreground="Black"/> </WrapPanel> <Label Name="WarningLabelTextLookOverPart4" HorizontalAlignment="Center" Content="you being prosecuted" FontWeight="Bold" Foreground="Black"/> </UniformGrid> </StackPanel> </Grid> 下次提问时,请提供最小的可重现示例,即将绑定更改为实际文本。
尝试从派生类向 GridViewDataColumn 添加过滤器
所以我有以下场景 具有列表绑定的 RadGridView 这是我的 XAML 所以我有以下场景 带有列表绑定的 RadGridView 这是我的 XAML <telerik:RadGridView x:Name="grid" Grid.Row="0" ItemsSource="{Binding BaseClassesList}" IsFilteringAllowed="True" IsReadOnly="true"> <telerik:RadGridView.Columns> <telerik:GridViewDataColumn DataMemberBinding="{Binding Name}" /> <telerik:GridViewDataColumn> <DataTemplate DataType="{x:Type DerivedClass}"> <TextBlock Text="{Binding WhatIWant}"/> </DataTemplate> </telerik:GridViewDataColumn> </telerik:RadGridView.Columns> </telerik:RadGridView> 这是我的视图模型 public List<BaseClass> BaseClassesList {get;set;} 这是我的基类 public class BaseClass { public string Name{ get; set; } public string Filler1{ get; set; } public string Filler2{ get; set; } } 这是我的派生类 public class DerivedClass : BaseClass { public string WhatIWant{ get; set; } } 如您所见,我绑定到了 BaseClasses 列表,一切正常,我可以获得我想要的所有信息。 但是,由于我正在访问 BaseClass 而不是 DerivedClass 的列表,因此 GridViewDataColumn 无法发挥其魔力并允许列筛选器工作。漏斗图标/按钮不出现。 除了此过滤功能之外,所有信息都正确显示在网格中 我尝试定义 DataTemplate、DataMemberPath、Filtering 标志,但到目前为止什么也没定义。 因此,经过大量的墙壁撞击和岩石粉碎之后,我终于找到了解决方案。 但在此之前,为了简单起见,我之前没有说的是我有第三个派生类,我想要访问的内容就在它上面 public class DerivedDerivedClass : DerivedClass { public string WhatIWant{ get; set; } //Removed from here } 第一件事是将我想要访问的内容移至基类的第一个派生 public class DerivedDerivedClass : DerivedClass { public string WhatIWant{ get; set; } //Removed from here } public class DerivedClass : BaseClass { public string WhatIWant{ get; set; } //Placed here } 在 XAML 网格中,我必须将 DataType 和 FilterMemberPath 添加到列中。我最初在 DataTemplate 上有 DataType,但这不起作用 <telerik:RadGridView.Columns> <telerik:GridViewDataColumn DataMemberBinding="{Binding Name}" /> <telerik:GridViewDataColumn DataType="{x:Type DerivedClass}" FilterMemberPath="WhatIWant"> <DataTemplate DataType="{x:Type DerivedClass}"> //DataType should not be defined here <TextBlock Text="{Binding WhatIWant}"/> </DataTemplate> </telerik:GridViewDataColumn> </telerik:RadGridView.Columns>
我正在尝试在WPF中设置PasswordBox的样式,以便它可以显示提示。 我通过在 ResourceDictionary 中使用以下代码来执行此操作: 我正在尝试在WPF中设置PasswordBox的样式,以便它可以显示Hint。 我通过在 ResourceDictionary 中使用以下代码来完成此操作: <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:BudgetBuddy.Styles"> <Style x:Key="PBHintStyle" TargetType="{x:Type PasswordBox}"> <Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.WindowBrushKey}}"/> <Setter Property="BorderBrush" Value="#FFABADB3"/> <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/> <Setter Property="BorderThickness" Value="1"/> <Setter Property="KeyboardNavigation.TabNavigation" Value="None"/> <Setter Property="HorizontalContentAlignment" Value="Left"/> <Setter Property="FocusVisualStyle" Value="{x:Null}"/> <Setter Property="AllowDrop" Value="True"/> <Setter Property="ScrollViewer.PanningMode" Value="VerticalFirst"/> <Setter Property="Stylus.IsFlicksEnabled" Value="False"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type PasswordBox}"> <Border x:Name="border" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" SnapsToDevicePixels="True" CornerRadius="4" Padding="5 2 0 0"> <Grid> <ScrollViewer x:Name="PART_ContentHost" Focusable="False" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden"/> <TextBlock x:Name="WARKTEXT" Text="{TemplateBinding Tag}" Foreground="DimGray" Visibility="Collapsed" /> </Grid> </Border> <ControlTemplate.Triggers> <Trigger Property="IsEnabled" Value="False"> <Setter Property="Opacity" TargetName="border" Value="0.56"/> </Trigger> <Trigger Property="IsMouseOver" Value="True"> <Setter Property="BorderBrush" TargetName="border" Value="#FF7EB4EA"/> </Trigger> <Trigger Property="IsKeyboardFocused" Value="True"> <Setter Property="BorderBrush" TargetName="border" Value="#FF569DE5"/> </Trigger> <MultiTrigger> <MultiTrigger.Conditions> <Condition Property="IsFocused" Value="False"/> </MultiTrigger.Conditions> <Setter Property="Visibility" TargetName="WARKTEXT" Value="Visible"/> </MultiTrigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> <Style.Triggers> <MultiTrigger> <MultiTrigger.Conditions> <Condition Property="IsInactiveSelectionHighlightEnabled" Value="True"/> <Condition Property="IsSelectionActive" Value="False"/> </MultiTrigger.Conditions> <Setter Property="SelectionBrush" Value="{DynamicResource {x:Static SystemColors.InactiveSelectionHighlightBrushKey}}"/> </MultiTrigger> </Style.Triggers> </Style> </ResourceDictionary> 这段代码可以工作,但有一个问题。它显示提示,将字符显示为密码字符,但问题是在字段中输入密码后,它会在密码字符上显示提示。 以下是一些截图: 问题是这样的: 我该如何解决这个问题?提前致谢。 :) 您可以尝试处理PasswordBox的PasswordChanged事件,并根据Password属性是否包含任何字符将其Tag属性设置为“True”或“False”,然后检查触发器中Tag属性的值 在 xaml 上: <Style x:Key="PasswordStyle" TargetType="{x:Type PasswordBox}"> <Setter Property="Tag" Value="False"/> <EventSetter Event="PasswordChanged" Handler="OnPasswordChanged"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type PasswordBox}"> <Border x:Name="border" CornerRadius="4" BorderBrush="LightGray" BorderThickness="4" Background="Transparent" SnapsToDevicePixels="True"> <Grid> <TextBlock x:Name="PassMessage" HorizontalAlignment="Left" VerticalAlignment="Center" Text=" Password..." FontSize="34" Margin="5,0,5,0" Foreground="LightGray" IsHitTestVisible="False" Visibility="Hidden"/> <ScrollViewer x:Name="PART_ContentHost" Focusable="False" HorizontalScrollBarVisibility="Hidden" BorderBrush="Transparent" VerticalScrollBarVisibility="Hidden"/> </Grid> </Border> <ControlTemplate.Triggers> <MultiTrigger> <MultiTrigger.Conditions> <Condition Property="Tag" Value="False"/> <Condition Property="IsKeyboardFocusWithin" Value="False"/> </MultiTrigger.Conditions> <Setter Property="Visibility" TargetName="PassMessage" Value="Visible"/> </MultiTrigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> <Grid> <PasswordBox x:Name="passwordBox" Style="{StaticResource PasswordStyle}" HorizontalAlignment="Left" Margin="217,256,0,0" VerticalAlignment="Top" Width="450"/> </Grid> 在 xaml.cs 上 private void OnPasswordChanged(object sender, RoutedEventArgs e) { passwordBox = sender as PasswordBox; passwordBox.Tag = (!string.IsNullOrEmpty(passwordBox.Password)).ToString(); } 希望这有帮助 你可以试试这个: <MultiTrigger> <MultiTrigger.Conditions> <Condition Property="IsFocused" Value="False"/> <Condition Property="Text" Value=""/> </MultiTrigger.Conditions> <Setter Property="Visibility" TargetName="WARKTEXT" Value="Visible"/> </MultiTrigger> <MultiTrigger> <MultiTrigger.Conditions> <Condition Property="IsFocused" Value="False"/> <Condition Property="Text" Value="{x:Null}"/> </MultiTrigger.Conditions> <Setter Property="Visibility" TargetName="WARKTEXT" Value="Visible"/> </MultiTrigger> 如果文本不为空或为空,则会显示提示,否则不显示。 希望对您有帮助。
有没有一种方法可以根据Excel的字符串排序逻辑升序对字符串进行排序,而无需编写自定义代码?
我有一个 Infragistics XamComboEditor,它需要根据 Excel 的升序排序逻辑对其值进行排序。它通过 绑定到 ObservableDictionary
InteractiveDataDisplay.WPF 制作动态图表作为值记录器外观
我使用 Microsoft InteractiveDataDisplay.WPF(以前的 DynamicDataDisplay)来可视化实时数据(大约 2-3 秒)。 这段代码xaml.cs: 公共部分类 MainWindow : 窗口 {
我在 Xaml 中有一个切换按钮和一个弹出窗口。弹出窗口的 IsOpen 绑定到切换按钮的 IsChecked,并且弹出窗口的 StaysOpen 设置为 false。因此,当选中切换按钮并且
我几乎没有尝试过将 Cognex In-Sight SDK 与 WPF 应用程序一起使用。 SDK 中有一些示例,但不幸的是仅适用于 WinForms。我想知道我可以为 WinForm 控件制作一个 Host...
创建一个仅响应字符按键和少数选定的编辑按键的 WPF 文本框
WPF 文本框响应相当多的编辑命令。我想消除绝大多数,并让它响应任何文本输入和一些编辑命令,如退格和删除。我...
我尝试在 WPF 中的鼠标光标旁边显示一个弹出窗口。窗口位置将在鼠标移动事件期间更新。主窗口是这样的: 我尝试在 WPF 中的鼠标光标旁边显示一个弹出窗口。窗口位置将在鼠标移动事件期间更新。主窗口是这样的: <Grid x:Name="_layoutGrid" Background="Transparent"> <DockPanel Background="Green"/> <Popup Name="_cursorInfo" IsHitTestVisible="False" AllowsTransparency="True" Placement="Relative" PlacementTarget="{Binding ElementName=_layoutGrid}"> <Border CornerRadius="1" Padding="1" Background="Blue" Opacity="0.7" IsHitTestVisible="False"> <TextBlock Text="Here is a content" IsHitTestVisible="False" /> </Border> </Popup> </Grid> 鼠标移动的事件处理程序如下: public MainWindow() { InitializeComponent(); _layoutGrid.MouseMove += LayoutGrid_MouseMove; _layoutGrid.MouseLeave += LayoutGrid_MouseLeave; } private void LayoutGrid_MouseLeave(object sender, MouseEventArgs e) { _cursorInfo.IsOpen = false; } private void LayoutGrid_MouseMove(object sender, MouseEventArgs e) { var pos = e.GetPosition(_layoutGrid); if (!_cursorInfo.IsOpen) { _cursorInfo.IsOpen = true; } _cursorInfo.HorizontalOffset = pos.X; _cursorInfo.VerticalOffset = pos.Y; Debug.WriteLine($"Pos: {pos}"); } 弹出窗口出现,但有很多“闪烁”。似乎鼠标很快就被捕获在弹出窗口中,导致闪烁。我还认识到,当我删除所包含边框的背景时,闪烁就消失了。不过我想看到边框的彩色背景。我认为设置“IsHitTestVisible”就足够了,但看来我错了。知道如何避免闪烁吗? 在光标的X和Y位置添加一些额外的偏移量,似乎可以解决问题 _cursorInfo.HorizontalOffset = pos.X + 10; _cursorInfo.VerticalOffset = pos.Y + 10;
<Setter Property="Height" Value="30" /> <Setter Property="Width&q...</desc> <question vote="0"> <pre><code><Style x:Key="AndroidToggleBtnStyle" TargetType="ToggleButton"> <Setter Property="Height" Value="30" /> <Setter Property="Width" Value="120" /> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="ToggleButton"> <Border x:Name="outborder" Padding="0" BorderBrush="{StaticResource BorderColorBrush}" BorderThickness="2" CornerRadius="10"> <Border x:Name="backgrd" Padding="0" Background="Transparent" CornerRadius="10"> <Border x:Name="inercircle" Width="20" Height="20" Margin="5,0,5,0" HorizontalAlignment="Left" Background="{StaticResource BorderColorBrush}" CornerRadius="100"> <ContentPresenter /> </Border> </Border> </Border> <ControlTemplate.Triggers> <Trigger Property="IsChecked" Value="True"> <Setter TargetName="outborder" Property="BorderBrush" Value="{StaticResource BackColorBlueBrush}" /> <Setter TargetName="backgrd" Property="Background" Value="{StaticResource BackColorBlueBrush}" /> <Setter TargetName="inercircle" Property="HorizontalAlignment" Value="Right" /> <Setter TargetName="inercircle" Property="Background" Value="{StaticResource BackColorWhiteBrush}" /> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> </code></pre> <p><a href="https://i.stack.imgur.com/qiH6v.png" target="_blank"><img src="https://cdn.txt58.com/i/AWkuc3RhY2suaW1ndXIuY29tL3FpSDZ2LnBuZw==" alt=""/></a></p> <p>它被定义并用作样式代码。 当选中时,背景颜色会发生变化。 不过outbound和backgrd还是有一点差距的。 我们如何填空?</p> </question> <answer tick="false" vote="0"> <p>这是一个愚蠢的问题。 我不应该将cornerradius 的值添加到backgrd 中。 删除声明的属性值后,运行正常。</p> </answer> </body></html>
WPF - WPFUI 库 - 图标不会在导航栏上呈现 C#
我正在使用 WPFUI 的演示模板来开发 WPF 应用程序,同时将新项目编辑到导航栏的列表中,直到您将鼠标悬停在导航栏列表中时,图标才会正确呈现,如
我怎样才能控制wrapanel,这样如果我删除了一个项目,顺序就不会改变
在列表视图中,我使用 Wrappanel 作为 ItemsPanelTemplate 在 listview 中,我使用 Wrappanel 作为 ItemsPanelTemplate <ListView ItemsSource="{Binding TodoItemViewModels}" ScrollViewer.VerticalScrollBarVisibility="Disabled" Drop="Card_Drop" AllowDrop="True" DragLeave="Card_DragLeave" IsEnabled="{Binding Disable, ElementName=root}" Background="Green"> <ListView.ItemsPanel> <ItemsPanelTemplate> <WrapPanel Margin="0" Orientation="Vertical" /> </ItemsPanelTemplate> </ListView.ItemsPanel> <!-- Displaying Cards in CardCollection View --> <ListView.ItemTemplate> <DataTemplate> <Border BorderThickness="2" BorderBrush="BlanchedAlmond" Opacity="1" Background="BlanchedAlmond" Width="25" Height="30" MouseMove="Card_MouseMove" CornerRadius="5" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"> <TextBlock Text="{Binding Cardstr}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Foreground="{Binding Cardclr}" Background="BlanchedAlmond" /> </Border> </DataTemplate> </ListView.ItemTemplate> </ListView> 我怎样才能修复Listview,所以如果我删除一个项目,它的位置将会有一个空槽,而不是像下面的图片那样重新排列列表: 我尝试了Wrapanel和Gridview都无法正常工作。 我不想在网格中逐个单元插入,因为这会使程序变得复杂 您不应移除卡,而应将其替换为代表空插槽的另一个对象。 例如,您可以向包含 IsEmpty 和 Cardstr 属性的类添加 Cardclr 属性,然后使用 DataTemplateSelector 基于此属性选择适当的模板: public class CustomTemplateSelector : DataTemplateSelector { public DataTemplate CardTemplate { get; set; } public DataTemplate EmptyTemplate { get; set; } public override DataTemplate SelectTemplate(object item, DependencyObject container) { var obj = item as YourClass; if (obj != null && obj.IsEmpty && EmptyTemplate != null) return EmptyTemplate; return CardTemplate; } } XAML:: <ListView ItemsSource="{Binding TodoItemViewModels}" ScrollViewer.VerticalScrollBarVisibility="Disabled" Drop="Card_Drop" AllowDrop="True" DragLeave="Card_DragLeave" IsEnabled="{Binding Disable, ElementName=root}" Background="Green"> <ListView.Resources> <DataTemplate x:Key="cardTemplate"> <Border BorderThickness="2" BorderBrush="BlanchedAlmond" Opacity="1" Background="BlanchedAlmond" Width="25" Height="30" MouseMove="Card_MouseMove" CornerRadius="5" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"> <TextBlock Text="{Binding Cardstr}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Foreground="{Binding Cardclr}" Background="BlanchedAlmond" /> </Border> </DataTemplate> <DataTemplate x:Key="emptyTemplate"> <Border> <TextBlock>empty...</TextBlock> </Border> </DataTemplate> </ListView.Resources> <ListView.ItemTemplateSelector> <local:CustomTemplateSelector CardTemplate="{StaticResource cardTemplate}" EmptyTemplate="{StaticResource emptyTemplate}"/> </ListView.ItemTemplateSelector> <ListView.ItemsPanel> <ItemsPanelTemplate> <WrapPanel Margin="0" Orientation="Vertical" /> </ItemsPanelTemplate> </ListView.ItemsPanel> </ListView>
在WPF中创建一个自定义ScrollViewer,它可以正常调整元素大小,并在子宽度小于其最小值时显示水平滚动条?
我正在开发一个 WPF 应用程序,我需要创建一个自定义 ScrollViewer,它可以根据可用宽度自动调整其子元素的大小。另外,当c的最小宽度...
我想通过在上面添加描述性标题(标签)来对 DataGrid 列进行分组: (前两列上方的“标题 1”) 调整列大小时,标签会按其应有的方式响应: (“他...
如何使 XAML DataGridColumns 填充整个 DataGrid?
我在 XAML(不是 Silverlight)中使用具有可调整大小的列的 DataGrid,如果用户调整屏幕大小,DataGrid 将展开。 目前如果所有 DataGrid 列的宽度都小于
我有一个 MediaElement 控件和几个视频,其构建操作设置为内容,并复制到设置为始终的输出目录。 如果我在 xaml 视图中显式设置源,如下所示: <