如果 SomeProperty 值为 10,我想更改 ListBox 中第一项的边距,而无需代码隐藏。这是我到目前为止:
<ListBox x:Class="Windows.CustomList"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Windows"
mc:Ignorable="d" x:Name="MyList"
d:DesignHeight="300" d:DesignWidth="300">
<ListBox.ItemContainerStyle>
<Style TargetType="{x:Type ListBoxItem}">
<Style.Triggers>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding Path=SomeProperty}" Value="10"/>
<Condition Binding="{Binding Path=Items.Count, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ListBox}}}" Value="1" />
</MultiDataTrigger.Conditions>
<Setter Property="Margin">
<Setter.Value>
<Thickness Left="500"/>
</Setter.Value>
</Setter>
</MultiDataTrigger>
</Style.Triggers>
</Style>
</ListBox.ItemContainerStyle>
<ListBox.ItemTemplate>
<DataTemplate>
<local:ListBoxItemCustomTemplate/>
</DataTemplate>
</ListBox.ItemTemplate>
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>
Run Code Online (Sandbox Code Playgroud)
当我尝试这种方法时,我得到:
System.Windows.Data 错误:4:无法找到引用“RelativeSource FindAncestor、AncestorType='ListBox'、AncestorLevel='1'”的绑定源。BindingExpression:Path=Items.Count; 数据项=空;目标元素是 'ListBox' (Name=''); 目标属性是“NoTarget”(类型“Object”)
如果我只有第一个条件,它会正确应用边距。我尝试的另一种方法是使用 ElementName:
这种方法不会出现任何错误,但也不起作用。
任何帮助将非常感激。
我编写了一个看板用户控件,我可以在其中将一些卡片从一列拖放到另一列(列表框/列表框项目),并且我使用了组件“ https://github.com/punker76/gong-wpf-dragdrop ”去做这个。现在我想添加一个新行为:显示一个预览阴影,卡片将被放置在附件中的动画 gif 中:

动画 gif 显示了执行此操作的 DevExpress 组件。我不想使用 DevExpress,而是想使用另一个开源组件,扩展 gong-wpf-dragdrop 或自己执行此操作。
是否有人已经这样做了或知道一个组件这样做?如果没有,有人有这样做的策略吗?
我很惊讶没有在谷歌上找到更多关于这个主题的信息。每个人都用 DevExpress 或 Telerik 做这样的事情吗?或者直到现在还没有人发布开源解决方案?
我有一个DataTemplate用来显示一个类的详细信息ListBox.在DataTemplate具有EventTrigger附接至该项目的Loaded一个使用事件DoubleAnimation的每个项目淡入视图,因为它们将被添加到ObservableCollection绑定到ListBox.它还有一个DataTrigger使用a DoubleAnimation和a ColorAnimation(RepeatBehavior="Forever")在特定条件下为发光效果设置动画.到现在为止还挺好.
该应用程序要求每隔几秒更新一次项属性.ListBox在调用时更新项目的属性后出现问题ListBox.Items.Refresh().这将重置动画,以便每个项目淡入视图,并且每隔几秒钟重新开始发光效果.如果我不调用,则item属性值不会更新Refresh.我的问题是,有没有办法单独刷新每个项目或以某种方式解决这个问题?
我使用Listbox来呈现一个表.它使用DisplayMemberPath来显示项目.
如何进行多重绑定以显示项目?
假设我想显示ID和NAME ......是否有模板示例等?
日Thnx
我有一个列表框,在datatemplate中我有一个Expander.
如果我单击Expander Header,扩展器将展开内容区域,但不会使父ListBoxItem选中.
如果我单击Expander的Expanded Content Zone,则会选择父ListBoxItem.
单击expandderHeader时如何使内容扩展并且父列表框项被选中?
在WPF应用程序中,我使用在XAML中的以下DataTemplate中定义的ItemTemplate创建Listbox:
<DataTemplate x:Key="ListItemTemplate">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<StackPanel>
<Button/>
<Button/>
<Button Name="btnRefresh" IsEnabled="false"/>
<TextBlock/>
<TextBlock/>
<TextBlock/>
<TextBlock/>
</StackPanel>
<TextBox/>
</Grid>
</DataTemplate>
Run Code Online (Sandbox Code Playgroud)
生成ListBox后,我需要在所有ListBoxItem上更改以下按钮IsEnabled propety为true: <Button Name="btnRefresh" IsEnabled="false"/>
问题:
我无法访问ListBoxItem,因此无法使用该按钮访问其子项.
在WPF中是否有像ListBox.Descendents()这样的Silverlight或任何其他方式来获取该按钮,
我在名为"电子邮件"的工作表中的列A中有一个名称列表
我想用名称列A填充userform ListBox.但是,我无法指定固定范围,因为此列表将增长和缩小.那么如何让userform使用正确数量的项目填充列表?
这是我目前正在尝试但不起作用(我相信这里有些人会明白为什么不这样做),我也看到了另一个使用简单For循环的例子,但我无法再找到这个例子给你看.
Private Sub UserForm_Initialize()
Dim rngName As Range
Dim rng1 As Range
Dim rng2 As Range
Dim ws As Worksheet
Set ws = Worksheets("Email")
Set rngName = ws.Range("A:A").Find(What:="*", LookAt:=xlWhole, MatchCase:=False, SearchOrder:=xlByRows, SearchDirection:=xlPrevious)
Set rng1 = ws.Range("A1")
On Error GoTo ErrorHandle
Me.lbUsed.List = Range(rng1 & ":" & rngName).Value
ErrorHandle:
End Sub
Run Code Online (Sandbox Code Playgroud)
我现在有以下代码,但是当我加载userform时它无法工作:
Private Sub UserForm_Initialize()
Dim rngName As Range
Dim rng1 As Range
Set rngName = Worksheets("Email").Range("A:A").Cells.Find(What:="*", LookAt:=xlWhole, MatchCase:=False, SearchOrder:=xlByRows, SearchDirection:=xlPrevious)
Set rng1 = Worksheets("Email").Range("A1:" & rngName.Address) …Run Code Online (Sandbox Code Playgroud) 我有一个很奇怪的问题,与工作时ListBox的一个WPF程序。我已经定义了我的ListBox SelectionModeas Single,但看起来即使在视觉上我无法选择多个项目,它也会发生在代码中。可以在这里看到:

在尝试解决方法时,我尝试使用 UnselectAll 函数,但奇怪的是,它仍然选择了一个项目:

作为最后的礼物,一旦选择了多个项目,如果我尝试单击我在代码中选择的未选择的可视化项目,我的应用程序会因 System.ArgumentException 而崩溃(我想它会尝试选择我的项目,该项目已被选中)事实上,它会因为添加一个完美的副本而崩溃?)

我查看了ListBox 甚至在具有相同问题的SelectionMode="Single"中选择了许多项目,但在我的情况下,我无法在视觉上选择多个项目,而且我的项目完全不同,所以它并没有真正的帮助。
我在 ListBox.Click 上没有任何自定义行为,这可能会弄乱某些东西......
myListBox.ItemsSource绑定到一个项目列表。我会在调用useItem它时减少所选项目的属性值,但它仍然是同一个项目(我不会重新创建它/删除它然后再次添加它)
我的问题来自哪里?我该如何解决?
如何在不从 Material Design 中删除样式的情况下更改 SelectedItem 的前景色?
这有效,但会从 Material Design 中删除样式:
<ListBox TextElement.Foreground="Black">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel IsItemsHost="True" />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Style.Triggers>
<Trigger Property="IsSelected" Value="True" >
<Setter Property="FontWeight" Value="Bold" />
<Setter Property="Background" Value="Transparent" />
<Setter Property="Foreground" Value="White" />
</Trigger>
</Style.Triggers>
<Style.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Transparent"/>
</Style.Resources>
</Style>
</ListBox.ItemContainerStyle>
</ListBox>
Run Code Online (Sandbox Code Playgroud)
我如何添加替换它的样式?
我正在尝试使用创建一个Windows 10天气应用程序。我需要一个来显示最近 10 天的天气部分。我必须为项目设置模板。我试过这个:WPFC#ListboxListbox
<ListBox Grid.Row="1" x:Name="DailyWeatherListBox">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel>
<!--...-->
</StackPanel>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>
Run Code Online (Sandbox Code Playgroud)
查看 Windows 10 天气。我将此图像放置在 Windows 10 中以废弃。我也不知道如何设置Scrollbar在Listbox角落。如果您能提供帮助,我将非常感激。
listbox ×10
listboxitem ×10
wpf ×9
c# ×5
.net ×1
childcontrol ×1
datatemplate ×1
excel ×1
excel-vba ×1
refresh ×1
templates ×1
vba ×1
xaml ×1