I created a style for custom button controls. This style is in ResourceDictionary.xaml (A file that has all user-defined management styles) in a COmmon project. I added a link to this COmmon project in my project, and also set the following in my xaml file:
<ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="pack://application:,,,/UTS.Pearl.BO.UI.Common;component/Styles/ResourceDictionary.xaml"/> </ResourceDictionary.MergedDictionaries>
The real style is given below. The problem is OnApplyTemplate in TMCVCARSButton.cs is never called. Any ideas?
<Style x:Key="{x:Type common:TMCVCARSButton}" BasedOn="{x:Null}" TargetType="{x:Type common:TMCVCARSButton}"> <Setter Property="FontFamily" Value="Arial" /> <Setter Property="FontSize" Value="12" /> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type common:TMCVCARSButton}"> <Grid Width="160" Margin="0,0,2,2"> <Rectangle RenderTransformOrigin="0.485,1" x:Name="rectangle" RadiusX="5" RadiusY="5" Opacity="1" Stroke="{DynamicResource Dark Gray}" StrokeThickness="1"> <Rectangle.Fill> <LinearGradientBrush EndPoint="0.037,-0.047" StartPoint="0.037,1.418"> <GradientStop Color="#FFCBC4C0" Offset="0.826"/> <GradientStop Color="#FFFDFBFB" Offset="1"/> <GradientStop Color="#FFDBD7D4" Offset="0"/> </LinearGradientBrush> </Rectangle.Fill> </Rectangle> <Viewbox Stretch="Fill" StretchDirection="DownOnly" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" x:Name="viewbox" OpacityMask="{x:Null}" > <ContentPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" RecognizesAccessKey="True" x:Name="contentPresenter" Visibility="Collapsed"/> </Viewbox> <WrapPanel Margin="4" Background="{x:Null}"> <Grid x:Name="_grdFrontLeft" Height="Auto" HorizontalAlignment="Left" VerticalAlignment="Top" MinWidth="75" MinHeight="75" Background="{x:Null}" Margin="0,2,2,0"> <Rectangle Stroke="Black" StrokeThickness="0.5"> <Rectangle.Fill> <LinearGradientBrush EndPoint="0.5,2.044" StartPoint="0.5,0"> <GradientStop Color="Black" Offset="0"/> <GradientStop Color="White" Offset="1"/> </LinearGradientBrush> </Rectangle.Fill> </Rectangle> <Viewbox x:Name="_vbxVCARSImageFrontLeft" Margin="0.5"> <Image x:Name="_imgFrontLeft" Width="Auto" Height="Auto"/> </Viewbox> </Grid> <Grid x:Name="_grdFrontRight" HorizontalAlignment="Left" Margin="0,2,0,0" MinHeight="75" MinWidth="75" VerticalAlignment="Top" Height="Auto" Background="{x:Null}"> <Rectangle Stroke="Black" StrokeThickness="0.5"> <Rectangle.Fill> <LinearGradientBrush EndPoint="0.5,2.044" StartPoint="0.5,0"> <GradientStop Color="Black" Offset="0"/> <GradientStop Color="White" Offset="1"/> </LinearGradientBrush> </Rectangle.Fill> </Rectangle> <Viewbox x:Name="_vbxVCARSImageFrontRight" Margin="0.5"> <Image x:Name="_imgFrontRight" Width="Auto" Height="Auto"/> </Viewbox> </Grid> <Grid x:Name="_grdRearLeft" HorizontalAlignment="Left" Margin="0,2,2,0" MinHeight="75" MinWidth="75" VerticalAlignment="Top" Height="Auto" Background="{x:Null}"> <Rectangle Stroke="Black" StrokeThickness="0.5"> <Rectangle.Fill> <LinearGradientBrush EndPoint="0.5,2.044" StartPoint="0.5,0"> <GradientStop Color="Black" Offset="0"/> <GradientStop Color="White" Offset="1"/> </LinearGradientBrush> </Rectangle.Fill> </Rectangle> <Viewbox x:Name="_vbxVCARSImageRearLeft" Margin="0.5"> <Image x:Name="_imgRearLeft" Width="Auto" Height="Auto"/> </Viewbox> </Grid> <Grid x:Name="_grdRearRight" HorizontalAlignment="Left" Margin="0,2,0,0" MinHeight="75" MinWidth="75" VerticalAlignment="Top" Height="Auto" Background="{x:Null}"> <Rectangle Stroke="Black" StrokeThickness="0.5"> <Rectangle.Fill> <LinearGradientBrush EndPoint="0.5,2.044" StartPoint="0.5,0"> <GradientStop Color="Black" Offset="0"/> <GradientStop Color="White" Offset="1"/> </LinearGradientBrush> </Rectangle.Fill> </Rectangle> <Viewbox x:Name="_vbxVCARSImageRearRight" Margin="0.5"> <Image x:Name="_imgRearRight" Width="Auto" Height="Auto"/> </Viewbox> </Grid> </WrapPanel> </Grid>
Thanks.
controls styles wpf
user296623
source share