这是我想要做的.我定义了2个数据模板,它们都引用了不同的用户控件.
<UserControl.Resources>
<DataTemplate x:Key="myDataTemplate1">
<Border BorderBrush="Black" BorderThickness="1">
<myUserControl1 />
</Border>
</DataTemplate>
<DataTemplate x:Key="myDataTemplate2">
<Border BorderBrush="Black" BorderThickness="1">
<myUserControl2/>
</Border>
</DataTemplate>
</UserControl.Resources>
Run Code Online (Sandbox Code Playgroud)
我使用这些数据模板使用ItemsControl显示项目列表,如下所示:
<ItemsControl x:Name="myItemList" ItemTemplate="{StaticResource myDataTemplate1}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate />
</ItemsControl.ItemsPanel>
</ItemsControl>
Run Code Online (Sandbox Code Playgroud)
我希望ItemTemplate有条件地是myDataTemplate1或myDataTemplate1,具体取决于整数变量的值分别为1或2.
我应该使用DataTriggers吗?还是有其他方法可以做到这一点?感谢帮助.
好吧,这绝对是一个新手问题,不幸的是无法找出/找到答案。
本质上是将对象列表绑定到组合框,当Disabled对象上的属性设置为 true 时,我希望将组合框项的文本颜色设置为灰色。
这是我到目前为止所拥有的:
组合框项数据类型
public class ListItem
{
public ListItem(string text)
{
Text = text;
}
public string Text { get; set; }
public bool Disabled { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
视图模型设置
public class MainPageViewModel : ReactiveObject
{
// In ReactiveUI, this is the syntax to declare a read-write property
// that will notify Observers, as well as WPF, that a property has
// changed. If we declared this as a normal property, we couldn't tell …Run Code Online (Sandbox Code Playgroud)