码迷,mamicode.com
首页 > Windows程序 > 详细

WPF 绑定Binding ElementName Path

时间:2018-08-30 18:24:21      阅读:596      评论:0      收藏:0      [点我收藏+]

标签:ice   div   key   alignment   mil   code   获取   resources   prope   

一:{Binding ElementName=grid0, Path=Height}

ElementName=grid0:查找到名为grid0的控件。

, Path=Height:获取名为grid0的控件的Height属性值。

即:Lb1的属性值设置为grid0控件的Height属性设置值。

    <Grid Name="grid0">
        <Grid>
            <StackPanel Background="AliceBlue">
                <Border HorizontalAlignment="Left" Height="30" Cursor="Hand" Panel.ZIndex="2">
                    <Label Content="返回" HorizontalAlignment="Left" MouseLeftButtonUp="Label_MouseLeftButtonUp"></Label>
                </Border>
                <Border VerticalAlignment="Top" Margin="0,-30,0,0">
                    <Label name="Lb1" Content="123" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Height="{Binding ElementName=grid0, Path=Height}" FontSize="28" FontFamily="微软雅黑"></Label>
                </Border>
            </StackPanel>
        </Grid>
    </Grid>

 二: {StaticResource LabelPanelStyle}

x:key属性值等于LabelPanelStyle的且类型为Lable的样式,加载到当前样式(Lable)中

<UserControl.Resources>
  <Style x:Key="LabelPanelStyle" TargetType="{x:Type Label}">
      <Setter Property="Foreground" Value="White"/>
  </Style>
</UserControl.Resources>
<Grid>
    <Label x:Name="borderControl"  FontFamily="微软雅黑" FontSize="20"  Background="#FF62A0CA" Content="123"  Style="{StaticResource LabelPanelStyle}"></Label>
</Grid>

 

WPF 绑定Binding ElementName Path

标签:ice   div   key   alignment   mil   code   获取   resources   prope   

原文地址:https://www.cnblogs.com/SeNaiTes/p/9561301.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!