samedi 15 novembre 2014

WPF and Control Templates


Vote count:

0




I implemented the following control template in a Shared User Control Library



<ControlTemplate x:Key="WindowTemplate" TargetType="{x:Type Window}">
<Border Name="Frame" Style="{StaticResource WindowBorder}" MouseLeftButtonDown="titleBar_MouseLeftButtonDown">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="50" />
<RowDefinition Height="*" />
<RowDefinition Height="40"/>
</Grid.RowDefinitions>
<controls:AppHeader Grid.Row="0" x:Name="Appheader" HeaderTitle="{Binding Path=AppTitle}" HeaderImageSource="{Binding Path=ImageSource}" ></controls:AppHeader>
<Border Grid.Row="1" BorderThickness="0,0,0,2" BorderBrush="#FFC1C1C1">
<ContentPresenter />
</Border>
<controls:AppNavigator Grid.Row="2" x:Name="AppNavigator"></controls:AppNavigator>
</Grid>
</Border>
</ControlTemplate>

<Style x:Key="WindowToolStyle" TargetType="Window">
<Setter Property="Height" Value="400"/>
<Setter Property="Width" Value="600"/>
<Setter Property="WindowStyle" Value="None" />
<Setter Property="ResizeMode" Value="NoResize"/>
<Setter Property="Topmost" Value="False"/>
<Setter Property="Template" Value="{StaticResource WindowTemplate}"/>
</Style>


I also have code behind file this resource file to implement common functions (like close, dragging window etc..)



public partial class WindowToolStyle : ResourceDictionary
{
public WindowToolStyle()
{
InitializeComponent();


}

private void titleBar_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
var window = (Window)((FrameworkElement)sender).TemplatedParent;
window.DragMove();
}

}


I then style my windows all with Style="{StaticResource WindowToolStyle}"


The problem is that I need to access the objects declared in the control template from the window that is being styled with this template, how do i do this? Thanks!



asked 1 min ago







WPF and Control Templates

Aucun commentaire:

Enregistrer un commentaire