Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 29th, 2012  |  syntax: None  |  size: 4.17 KB  |  hits: 20  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. WPF Dependency Properties Settings binding doesnt update
  2. public static readonly DependencyProperty FileTextProperty;
  3.    //Constructor
  4.        static FileButton()
  5.        {
  6.         DefaultStyleKeyProperty.OverrideMetadata(typeof(FileButton), new FrameworkPropertyMetadata(typeof(FileButton)));
  7.  
  8.  
  9.         // Initialize dependency properties
  10.         FileTextProperty = DependencyProperty.Register("FileText", typeof(string), typeof(FileButton),   new UIPropertyMetadata ("Default File Text"));
  11.         }
  12.  
  13.       /// <summary>
  14.     /// The Filename text displayed by the button.
  15.     /// </summary>
  16.     [Description("The text displayed by the button."), Category("Common Properties")]
  17.     public string FileText
  18.     {
  19.         get { return (string)GetValue(FileTextProperty); }
  20.         set { SetValue(FileTextProperty, value); }
  21.     }
  22.        
  23. <Style x:Key="ButtonFocusVisual">
  24.                         <Setter Property="Control.Template">
  25.                             <Setter.Value>
  26.                                 <ControlTemplate>
  27.                                     <Rectangle Margin="2" SnapsToDevicePixels="true" Stroke="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" StrokeThickness="1" StrokeDashArray="1 2"/>
  28.                                 </ControlTemplate>
  29.                             </Setter.Value>
  30.                         </Setter>
  31.                     </Style>
  32.  
  33.                     <Style x:Key="GradientStyle" TargetType="{x:Type Button}">
  34.                         <Setter Property="FocusVisualStyle" Value="{StaticResource ButtonFocusVisual}"/>
  35.                         <Setter Property="Background" Value="{StaticResource ButtonNormalBackground}"/>
  36.                         <Setter Property="BorderBrush" Value="{StaticResource ButtonNormalBorder}"/>
  37.                         <Setter Property="BorderThickness" Value="1"/>
  38.                         <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
  39.                         <Setter Property="HorizontalContentAlignment" Value="Center"/>
  40.                         <Setter Property="VerticalContentAlignment" Value="Center"/>
  41.                         <Setter Property="Padding" Value="1"/>
  42.                         <Setter Property="Template">
  43.                             <Setter.Value>
  44.  
  45.                                 <ControlTemplate TargetType="{x:Type local:FileButton}">
  46.                                     <Grid x:Name="main" MinHeight="38" MaxHeight="38">
  47.  
  48.                                         <Grid Margin="4,0" Name="DisplayMain">
  49.                                             <Grid.ColumnDefinitions>
  50.                                                 <ColumnDefinition Width="Auto"/>
  51.                                                 <ColumnDefinition/>
  52.                                             </Grid.ColumnDefinitions>
  53.                                             <Grid.RowDefinitions>
  54.                                                 <RowDefinition/>
  55.                                             </Grid.RowDefinitions>
  56.                                             <TextBlock x:Name="fileText" HorizontalAlignment="Stretch" Text="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=local:FileButton, AncestorLevel=1}, Path=FileText}" TextWrapping="NoWrap" VerticalAlignment="Top" Grid.Column="0" Margin="4,0,0,0" TextTrimming="WordEllipsis"/>
  57.                                         </Grid>
  58.                                     </Grid>
  59.                                 </ControlTemplate>
  60.                             </Setter.Value>
  61.                         </Setter>
  62.                     </Style>
  63.  
  64.                 </ControlTemplate.Resources>
  65.  
  66.                 <Grid x:Name="LayoutRoot" Margin="0">
  67.                     <local:FileButton Style="{DynamicResource GradientStyle}"/>
  68.                 </Grid>
  69.             </ControlTemplate>
  70.         </Setter.Value>
  71.     </Setter>
  72. </Style>
  73.        
  74. <Grid x:Name="LayoutRoot">
  75.     <Button VerticalAlignment="Top" Margin="132,140,168,0" Height="54.96">
  76.         <StackPanel>
  77.             <Image Source="{Binding Icon}"></Image>
  78.             <TextBlock Text="{Binding FileName}" HorizontalAlignment="Left"/>
  79.         </StackPanel>
  80.     </Button>
  81. </Grid>
  82.        
  83. <TextBlock Text="{TemplateBinding FileText}" />