zoukankan      html  css  js  c++  java
  • WPF中一个控件绑定另一个控件的属性

    如同一个Grid中的一个按钮根据另一个按钮的显示与否作出不同的响应:

    绑定的时候通过ElementName来指定控件

    <Grid Margin="50,130">
      <Grid.ColumnDefinitions>
        <ColumnDefinition/>
        <ColumnDefinition Width="40"/>
      </Grid.ColumnDefinitions>
      <Button Content="asdfasdfadsfa" Background="Aquamarine">
        <Button.Style>
          <Style TargetType="{x:Type Button}">
            <Setter Property="Template">
              <Setter.Value>
                <ControlTemplate TargetType="{x:Type Button}">
                  <Border x:Name="bd" BorderBrush="Black" Background="{TemplateBinding Background}" BorderThickness="1" CornerRadius="6,0,0,6" >
                    <TextBlock VerticalAlignment="Center" HorizontalAlignment="Center" Text="{TemplateBinding Content}"/>
                </Border>
              <ControlTemplate.Triggers>
                <DataTrigger Binding="{Binding ElementName=btn2,Path=Visibility}" Value="Collapsed">
                  <Setter TargetName="bd" Property="CornerRadius" Value="6,6,6,6"/>
                </DataTrigger>
              </ControlTemplate.Triggers>
            </ControlTemplate>
          </Setter.Value>
        </Setter>
      </Style>
    </Button.Style>


      </Button>
        <Button  x:Name="btn2" Grid.Column="2" Command="{Binding MainCommand}" Background="Beige">
          <Button.Style>
            <Style TargetType="{x:Type Button}">
              <Setter Property="Template">
                <Setter.Value>
                  <ControlTemplate TargetType="{x:Type Button}">
                    <Border BorderBrush="Black" Background="{TemplateBinding Background}" BorderThickness="0,1,1,1" CornerRadius="0,6,6,0" >

                      <Path Data="M 0,0 L 20,0 L 10,10 Z" Fill="Black" VerticalAlignment="Center" HorizontalAlignment="Center"/>
                    </Border>
                  </ControlTemplate>
                </Setter.Value>
              </Setter>
            </Style>
          </Button.Style>
        </Button>
    </Grid>

  • 相关阅读:
    echarts统计图使用
    ecshop 后台 审核功能
    ecshop 后台时间调用
    ecshop 后台分页功能
    ecshop 实现购物车退出不清空
    通过Measure & Arrange实现UWP瀑布流布局
    UWP中的Direct2D
    微软颜龄 维护小记——布局的小智慧
    Win10 UWP开发中的重复性静态UI绘制小技巧 2
    Win10 UWP开发中的重复性静态UI绘制小技巧 1
  • 原文地址:https://www.cnblogs.com/tommy-huang/p/6516093.html
Copyright © 2011-2022 走看看