![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
| |
| | #1 (permalink) |
| | Set BorderThickness.Top Property in Trigger with TemplateBinding Hi @all, I would like a custom style and template for my controls design. in my control template, i have many borders and other controls. For one or more borders i would like use different borders(Top,Bottom and Left and die other not). In the C#- Codebehind i have create a dependency property from type double. In my ResourceDictionary i would like use the dependency property in a Tricker. Here is my Example. C#---------- ...... public double TopBorderThickness { get { return (double)GetValue(TopBorderThicknessProperty); } set { SetValue(TopBorderThicknessProperty, value); } } // Using a DependencyProperty as the backing store for TopBorderThickness. This enables animation, styling, binding, etc... public static readonly DependencyProperty TopBorderThicknessProperty = DependencyProperty.Register("TopBorderThickness", typeof(double), typeof(MyButton), new UIPropertyMetadata(0.0)); ....... C#---------- ResourceDictionary-------------------- <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:MyNamespace="clr-namespace:WindowsApplication1" > <Style x:Key="{x:Type MyNamespace:MyButton}" TargetType="{x:Type MyNamespace:MyButton}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type MyNamespace:MyButton}"> <Grid x:Name ="m_ButtonGrid" > <Grid.ColumnDefinitions> <ColumnDefinition Width="0.5*" /> <ColumnDefinition /> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition Height="0.5*" /> <RowDefinition /> </Grid.RowDefinitions> <Border x:Name ="m_ButtonBackground" Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="0" Grid.RowSpan="2" Background="DarkGray" BorderBrush="AliceBlue" > </Border> </Grid> <ControlTemplate.Triggers> <Trigger Property="ShowTopBorder" Value="True"> <Setter TargetName="m_ButtonBackground" Property="Thickness.Top" Value="{TemplateBinding TopBorderThickness}" /> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> </ResourceDictionary> ResourceDictionary-------------------- When i run my application, the compiler write the following error message. Error at element 'Setter' in markup file 'WindowsApplication1;component/MyButtonStyle.xaml' : 'Thickness.Top' property is not a DependencyProperty on the Template's TargetType class 'System.Windows.Controls.Border'. Verify the Template's TargetType, or use Class.Property syntax to specify the property. Wat is my error? Can i not set the Thickness.Top property? Thanks for help. TOM_MUE www.tom-mue.de |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Set BorderThickness.Top Property in Trigger with TemplateBinding "Thickness" or even "Thickness.Top" are not existing properties... However, Control class defines a BorderThickness property of type Thickness... Thickness is a structure with Left, Right, Bottom and Top members, which can be set independently... It can also be done in XAML: <Control BorderThickness="3" /> --> This sets all 4 members to "3" <Control BorderThickness="3,4,5,6" /> --> left,top,right,bottom Otherwise, you can build a converter which builds a thickness based on the parameters you wish! What you are looking for is the Border.BorderThickness Thomas Mueller wrote: > Hi @all, > > I would like a custom style and template for my controls design. in my > control template, i have many borders and other controls. For one or more > borders i would like use different borders(Top,Bottom and Left and die other > not). In the C#- Codebehind i have create a dependency property from type > double. In my ResourceDictionary i would like use the dependency property in > a Tricker. Here is my Example. > > C#---------- > ..... > public double TopBorderThickness > { > get { return (double)GetValue(TopBorderThicknessProperty); } > set { SetValue(TopBorderThicknessProperty, value); } > } > > // Using a DependencyProperty as the backing store for > TopBorderThickness. This enables animation, styling, binding, etc... > public static readonly DependencyProperty TopBorderThicknessProperty = > DependencyProperty.Register("TopBorderThickness", > typeof(double), typeof(MyButton), new UIPropertyMetadata(0.0)); > > ...... > C#---------- > > ResourceDictionary-------------------- > > <ResourceDictionary > xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" > xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" > xmlns:MyNamespace="clr-namespace:WindowsApplication1" > > > <Style x:Key="{x:Type MyNamespace:MyButton}" TargetType="{x:Type > MyNamespace:MyButton}"> > <Setter Property="Template"> > <Setter.Value> > <ControlTemplate TargetType="{x:Type MyNamespace:MyButton}"> > <Grid x:Name ="m_ButtonGrid" > > > <Grid.ColumnDefinitions> > <ColumnDefinition Width="0.5*" /> > <ColumnDefinition /> > </Grid.ColumnDefinitions> > <Grid.RowDefinitions> > <RowDefinition Height="0.5*" /> > <RowDefinition /> > </Grid.RowDefinitions> > <Border x:Name ="m_ButtonBackground" > Grid.Column="0" > Grid.ColumnSpan="2" > Grid.Row="0" > Grid.RowSpan="2" > Background="DarkGray" > BorderBrush="AliceBlue" > > > </Border> > </Grid> > <ControlTemplate.Triggers> > <Trigger Property="ShowTopBorder" Value="True"> > <Setter TargetName="m_ButtonBackground" > Property="Thickness.Top" Value="{TemplateBinding TopBorderThickness}" /> > </Trigger> > </ControlTemplate.Triggers> > </ControlTemplate> > </Setter.Value> > </Setter> > </Style> > </ResourceDictionary> > > ResourceDictionary-------------------- > > When i run my application, the compiler write the following error message. > > Error at element 'Setter' in markup file > 'WindowsApplication1;component/MyButtonStyle.xaml' : 'Thickness.Top' property > is not a DependencyProperty on the Template's TargetType class > 'System.Windows.Controls.Border'. Verify the Template's TargetType, or use > Class.Property syntax to specify the property. > > Wat is my error? Can i not set the Thickness.Top property? > > Thanks for help. > > TOM_MUE > www.tom-mue.de |
My System Specs![]() |