Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 向某些控件添加换行_C#_Asp.net_Xaml_Silverlight - Fatal编程技术网

C# 向某些控件添加换行

C# 向某些控件添加换行,c#,asp.net,xaml,silverlight,C#,Asp.net,Xaml,Silverlight,我需要添加包装到我的单选按钮控件,除了一个窗口上的。当单选按钮添加到不需要换行的其他页面时,我一直在试图弄清楚如何有条件地从控件中删除或更改换行面板的值 这是添加包装的编码 XAML <Style TargetType="auc:APRadioButtonListBox"> <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Disabled" /> &l

我需要添加包装到我的单选按钮控件,除了一个窗口上的。当单选按钮添加到不需要换行的其他页面时,我一直在试图弄清楚如何有条件地从控件中删除或更改换行面板的值

这是添加包装的编码

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">

有谁能告诉我如何在没有包装的情况下将单选按钮添加到另一个页面上。

由于您在应用程序级别应用了样式,因此它将隐式应用于与其目标类型匹配的所有控件。您有两个选项可以在不包装的情况下获取页面

  • 使用忽略换行的样式替代所需页面上的样式
  • 为默认样式指定一个键,并在需要的地方显式应用它,而其他人则没有包装
如果不需要包装的页面比需要包装的页面多,则后者是有意义的。考虑下面的

<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}" />


任何未明确引用此样式的其他样式都将获得默认设置。或者,您可以定义其他样式而不进行换行,并为其提供一个键,以便应用于不需要换行的页面。

由于您在应用程序级别应用了样式,因此它将隐式应用于与其目标类型匹配的所有控件。您有两个选项可以在不包装的情况下获取页面

  • 使用忽略换行的样式替代所需页面上的样式
  • 为默认样式指定一个键,并在需要的地方显式应用它,而其他人则没有包装
如果不需要包装的页面比需要包装的页面多,则后者是有意义的。考虑下面的

<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}" />


任何未明确引用此样式的其他样式都将获得默认设置。或者,您可以定义其他样式而不进行换行,并为其提供一个键,该键可应用于不需要换行的页面。

在不需要换行的页面上创建一个从base派生的新样式,并覆盖样式设置器

<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}"/>

在不需要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}"/>


此样式是在什么级别定义的?应用程序资源字典,或特定页面/容器控件?应用程序资源字典@FabuluSat此样式定义的级别是什么?应用程序资源字典,或特定页面/容器控件?应用程序资源字典@Fableus