wpf 如何更改绑定到控件模版

自己现在想修改一人控件模版的外观,就是想根据不同的情况来修改,很自然的要用到绑定,可是绑定只能是依赖属性啊,我就写了一个依赖属性,可是后来发现怎么用,怎么改依赖属性的值都不会传过去,传过到模版 上的都是依赖属性的初始值,后来我又想动太的改变依赖属性的初始值,可是后来发现自己水平实现不了,
谁要是有办法给我说一下啊,
后来我的解决办法就是不去动态的修改控件模版了而是要用一个静态的样式来调用把控件模版包括起来,这样的话就可以直接修改外观的样式,这样就可以用普通属性来进行绑定了。、
以下是源码

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:s="clr-namespace:MysherOCRReader"
                    xmlns:c="clr-namespace:MysherOCRReader.doubleClass">



  <ResourceDictionary.MergedDictionaries>
    <ResourceDictionary Source="MoveThumb.xaml"/>
    <ResourceDictionary Source="ResizeDecorator.xaml"/>
    <ResourceDictionary Source="RotateDecorator.xaml"/>
  </ResourceDictionary.MergedDictionaries>

  <!-- ContentControl style to move, resize and rotate items -->
  <Style x:Key="DesignerItemStyle" TargetType="ContentControl">
        <Style.Resources>
            <c:ChangeRegionColor x:Key="change_background"/>
            <c:GetPhotoInfoRegionCollection x:Key="REgionCollection"/>
            <s:RegionInfo x:Key="RegionCollection"></s:RegionInfo>

        </Style.Resources>
            <Setter Property="MinHeight" Value="10"/>
    <Setter Property="MinWidth" Value="10"/>    
    <Setter Property="RenderTransformOrigin" Value="0.5,0.5"/>
    <Setter Property="SnapsToDevicePixels" Value="true"/>
        <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="ContentControl" >
                    <Border  DataContext="{StaticResource RegionCollection}" >
                        <Grid x:Name="grd1" Opacity="0.4" Background="{Binding OCRType,Converter={StaticResource change_background},UpdateSourceTrigger=PropertyChanged}">
                            <Label x:Name="lab_flag" Content="Mysher编号" Height="250" Width="250" Foreground="Black"></Label>
                            <Grid DataContext="{Binding RelativeSource={RelativeSource TemplatedParent}}"  >
            <Control Name="RotateDecorator"
                     Template="{StaticResource RotateDecoratorTemplate}"
                     Visibility="Collapsed"/>
              <s:MoveThumb x:Name="MoveThumbDecorator" Template="{StaticResource MoveThumbTemplate}"
                         Cursor="Hand" />
            <Control x:Name="ResizeDecorator"
                     Template="{StaticResource ResizeDecoratorTemplate}"
                     Visibility="Collapsed"/>
            <ContentPresenter Content="{TemplateBinding ContentControl.Content}"/>
          </Grid>
                        </Grid>
                    </Border>
                    <ControlTemplate.Triggers>
            <Trigger Property="Selector.IsSelected" Value="True">
              <Setter TargetName="ResizeDecorator" Property="Visibility" Value="Visible"/>
              <Setter TargetName="RotateDecorator" Property="Visibility" Value="Collapsed"/>
                <Setter TargetName="MoveThumbDecorator" Property="Visibility" Value="Visible"/>
                        </Trigger>
          </ControlTemplate.Triggers>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

</ResourceDictionary>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值