WPF的控件Binding的ElementName/RelativeSource具体用法

<TextBlock Name="_txtSickBedNo" FontStyle="Normal" Foreground="Black" Margin="6,2,1,2"  FontWeight="Bold"/>

<TextBlock Text="床"  FontStyle="Normal" Foreground="Black" Margin="0,2,6,2"  HorizontalAlignment="Left" VerticalAlignment="Center" FontWeight="Bold" 

                       Visibility="{Binding ElementName=_txtSickBedNo, Path=Text, Converter={StaticResource NullEmptyToVisibilityConverter}}" />
<Border Grid.Row="3" Grid.Column="0" Height="25" Visibility="{Binding ElementName=_chkNeedlessSickBed,Path=Visibility}">

    <CheckBox Name="_chkNeedlessSickBed" Content="免分配床位" VerticalAlignment="Center" Margin="45,0,0,0" />

</Border>
<ToggleButton Name="ToggleButton" Template="{StaticResource ComboBoxToggleButton}" Grid.Column="2" 

    Focusable="false" IsChecked="{Binding Path=IsDropDownOpen,Mode=TwoWay,RelativeSource={RelativeSource TemplatedParent}}" ClickMode="Press">

</ToggleButton>
<TextBlock Visibility="{Binding Converter={x:Static js:Converters.BooleanToVisibility}, Path=IsDefaultOrEmpty, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl}}" 

    FontStyle="Italic" Foreground="Gray" 

    Text="{Binding Path=DefaultText,Mode=OneWay,RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl}}">

</TextBlock>
<Label Grid.Column="1" Name="_lblStatus" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Center" Foreground="Red" Background="Linen" Visibility="{Binding RelativeSource={RelativeSource Self}, Path=Content, Converter={StaticResource NullEmptyToVisibilityConverter}}" />

 

<StackPanel Orientation="Horizontal">

    <TextBlock Text="{Binding MbulatoriumDiagnose.Disease.Name}" />

    <TextBlock Text="(" Visibility="{Binding ElementName=_txtMbulatoriumDiagnose, Path=Text, Converter={StaticResource NullEmptyToVisibilityConverter}}" />

    <TextBlock Name="_txtMbulatoriumDiagnose" Text="{Binding MbulatoriumDiagnose.Description}"/>

    <TextBlock Text=")" Visibility="{Binding ElementName=_txtMbulatoriumDiagnose, Path=Text, Converter={StaticResource NullEmptyToVisibilityConverter}}" />

</StackPanel>

 

你可能感兴趣的:(relative)