[英]Add wrapping to certain controls
我需要将换行添加到我的“单选按钮”控件中,但只在一个窗口中。 我一直试图找出当单选按钮添加到不需要换行的其他页面时,如何有条件地从控件中删除或更改换行面板的值。
这是添加包装的代码。
XAML
<Style TargetType="auc:APRadioButtonListBox">
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Disabled" />
<Setter Property="IsTabStop" Value="True" />
<Setter Property="FontSize" Value="{StaticResource FontSize}" />
<Setter Property="Margin" Value="-2,0,0,0" />
<Setter Property="ItemsPanel">
<Setter.Value>
<ItemsPanelTemplate>
<toolkit:WrapPanel Background="Transparent" ItemWidth="Auto" x:Name="RadioListWrapPanel" Orientation="Horizontal" />
</ItemsPanelTemplate>
</Setter.Value>
</Setter>
<Setter Property="ItemTemplate">
C#
public virtual ItemsPanelTemplate ItemsPanel { get; set; }
有人可以建议我如何在不包装的情况下将单选按钮添加到另一页吗?
由于已在应用程序级别应用了样式,因此它将隐式应用于与目标类型匹配的所有控件。 您有两种选择来获取页面而不进行包装...
如果不需要的页面多于不需要的页面,则后者是有意义的。 考虑以下
<Style x:Key="WrappedRadioButtons" TargetType="auc:APRadioButtonListBox">
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Disabled" />
<Setter Property="IsTabStop" Value="True" />
<Setter Property="FontSize" Value="{StaticResource FontSize}" />
<Setter Property="Margin" Value="-2,0,0,0" />
<Setter Property="ItemsPanel">
<Setter.Value>
<ItemsPanelTemplate>
<toolkit:WrapPanel Background="Transparent" ItemWidth="Auto" x:Name="RadioListWrapPanel" Orientation="Horizontal" />
</ItemsPanelTemplate>
</Setter.Value>
</Setter>
<Setter Property="ItemTemplate">
</Style>
现在,在需要应用此样式的页面中,您可以执行以下操作:
<uac:APRadioButtonListBox Style="{StaticResource WrappedRadioButtons}" />
其他未明确引用此样式的对象将获得默认设置。 另外,您可以定义其他样式而不进行包装,并为其指定一个密钥,该密钥可应用于不需要包装的页面。
在不需要WrapPanel的页面上创建从基本派生的新样式并覆盖样式设置器
<Style TargetType="auc:APRadioButtonListBox"
BasedOn="{StaticResource {x:Type auc:APRadioButtonListBox}}">
<Setter Property="ItemsPanel">
<Setter.Value>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</Setter.Value>
</Setter>
</Style>
或者只是对auc:APRadioButtonListBox元素执行此操作:
<auc:APRadioButtonListBox>
<auc:APRadioButtonListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</auc:APRadioButtonListBox.ItemsPanel>
</auc:APRadioButtonListBox>
或者在资源字典中定义一个不设置ItemsPanel的命名样式。 默认样式将对其进行扩展。 并在不需要包装的一页上使用命名样式:
<Style TargetType="auc:APRadioButtonListBox" x:Key="APRadioButtonListBoxStyle">
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Disabled" />
<Setter Property="IsTabStop" Value="True" />
<Setter Property="FontSize" Value="{StaticResource FontSize}" />
<Setter Property="Margin" Value="-2,0,0,0" />
</Style>
<Style TargetType="auc:APRadioButtonListBox" BasedOn="{StaticResource APRadioButtonListBoxStyle}">
<Setter Property="ItemsPanel">
<Setter.Value>
<ItemsPanelTemplate>
<toolkit:WrapPanel Background="Transparent" ItemWidth="Auto" x:Name="RadioListWrapPanel" Orientation="Horizontal" />
</ItemsPanelTemplate>
</Setter.Value>
</Setter>
</Style>
<auc:APRadioButtonListBox Style="{StaticResource APRadioButtonListBoxStyle}"/>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.