[英]How to set the Style property of a ListBox control in code
I have a part of Xaml code that I want to write in C# code. 我有一部分Xaml代码,我想用C#代码编写。 Code:
码:
<ListBox Name="listBox">
<ListBox.ItemContainerStyle>
<Style TargetType="{x:Type ListBoxItem}">
<Setter Property="Focusable" Value="False"/>
</Style>
</ListBox.ItemContainerStyle>
</ListBox>
I tried: 我试过了:
listBox.ItemContainerStyle = new Style();
Setter setter = new Setter();
setter.Property = ....??
setter.Value = true;
listBox.ItemContainerStyle.Setters.Add(setter);
But cant find the Focusable property to insert in setter. 但无法找到要在setter中插入的Focusable属性。 Can anyone help?
有人可以帮忙吗?
This will work just fine. 这将工作得很好。
Style style = new Style(typeof(ListBoxItem));
style.Setters.Add(new Setter(ListBoxItem.FocusableProperty, false));
listBox.ItemContainerStyle = style;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.