0

こんにちは、ラベルとエキスパンダー コントロールの角を丸くしたスタイルを作成してみます。

ラベルのスタイル:

        <Style x:Key="InfoLabelStyle" TargetType="{x:Type Label}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type Label}">
                        <Border Name="Border" Background="#BFE3FE" BorderBrush="#BFE3FE" BorderThickness="1" CornerRadius="7" Padding="3">
                        </Border>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
            <Setter Property="FontSize" Value="12"/>
            <Setter Property="FontWeight" Value="Normal"/>
            <Setter Property="Height" Value="25"/>
            <Setter Property="VerticalAlignment" Value="Center"/>
            <Setter Property="BorderThickness" Value="1"/>
            <Setter Property="BorderBrush" Value="#BFE3FE"/>
            <Setter Property="Background" Value="#BFE3FE"/>
            <Setter Property="Margin" Value="2,4,0,1" />
            <Setter Property="Padding" Value="4,0,0,0" />
        </Style>

ビューでこのスタイルにマルチバインディングを使用します。

                 <Label Style="{StaticResource InfoLabelStyle}">
                        <Label.Content>
                            <MultiBinding StringFormat="{}{0}, {1} rokov">
                                <Binding Path="Oponent.Info.Sex" Converter="{StaticResource sexConverter}"/>
                                <Binding Path= "Oponent.Info.Age"/>
                            </MultiBinding>
                        </Label.Content>
                      </Label>

しかし、アプリを実行すると、このラベルの内容は空で、バインディングは良好で、textBox コントロールで試してみると動作します。

2 つ目の問題は、エキスパンダー コントロールの角も丸くしたいということです。

ラベルスタイルと同じ方法を試します:

        <Style x:Key="InfoExpanderStyle" TargetType="{x:Type Expander}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type Expander}">
                        <Border Name="Border" Background="#BFE3FE" BorderBrush="#BFE3FE" BorderThickness="1" CornerRadius="7" Padding="3">
                        </Border>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

Expander コントロールの Applu スタイル:

     <Expander Name="InfoExapnder" 
                      Header="{Binding Path=Oponent.Info.Nick, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"
                      Style="{StaticResource InfoExpanderStyle}"
                      IsExpanded="True"
                      FontSize="18"
                      FontWeight="Normal"
                      Background="#ECEBEB" 
                      Margin="3,0,3,0"
                      Grid.Row="0">
                <Grid>
</Grid>

しかし、結果は同じで、コントロールの内容は空です。

私が悪いことをしますか?

4

1 に答える 1

1

テンプレートを再作成したが、コンテンツを配置する場所を指定していないため、ラベルは空です。次のようなものが必要です。

                <ControlTemplate TargetType="{x:Type Label}">
                    <Border Name="Border" Background="#BFE3FE" BorderBrush="#BFE3FE" BorderThickness="1" CornerRadius="7" Padding="3">
                        <ContentPresenter Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}"/>
                    </Border>
                </ControlTemplate>
于 2011-01-19T18:16:39.043 に答える