同时使用Binding&StringFormat 显示Text【项目】

 

Case ID?unit

红色的字根据一个后台boolean来做trigger,可以是Case or Open

蓝色的字binding到后台的一个string属性来切换任意的Unit单位

这样一共有6中组合:

Case ID (in)      OpenID (in)

Case ID (cm)      OpenID (cm)

Case ID (mm)       OpenID (mm)

 

上图两个红圈的字分别控制显示那个Text

 

代码如下:

<ControlTemplate x:Key="HoleTypeInfo_template">
        <Grid>
            <TextBlock x:Name="CaseIDText"
                       HorizontalAlignment="Center"
                       VerticalAlignment="Center"
                       FontSize="10pt"
                       Foreground="#FF404041"
                       Style="{StaticResource Univers57_Condensed}"
                       Text="{Binding HoleIDUnit,
                                      StringFormat=Case ID ({0})}" />
            <TextBlock x:Name="OpenIDText"
                       HorizontalAlignment="Center"
                       VerticalAlignment="Center"
                       FontSize="10pt"
                       Foreground="#FF404041"
                       Style="{StaticResource Univers57_Condensed}"
                       Text="{Binding HoleIDUnit,
                                      StringFormat=Hole ID ({0})}" />
        </Grid>
        <ControlTemplate.Triggers>
            <DataTrigger Binding="{Binding IsOpenHole}" Value="True">
                <Setter TargetName="CaseIDText" Property="Visibility" Value="Collapsed" />
                <Setter TargetName="OpenIDText" Property="Visibility" Value="Visible" />
            </DataTrigger>
            <DataTrigger Binding="{Binding IsOpenHole}" Value="False">
                <Setter TargetName="CaseIDText" Property="Visibility" Value="Visible" />
                <Setter TargetName="OpenIDText" Property="Visibility" Value="Collapsed" />
            </DataTrigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

 

 

 

posted @ 2013-09-05 10:43  若愚Shawn  阅读(356)  评论(0编辑  收藏  举报