|
-
Feb 8th, 2011, 01:09 AM
#1
Thread Starter
Member
[RESOLVED] [WPF/C#] Xaml Events
Hey everyone, I ran into a small snag in my most recent project. I'm new to WPF (as well as xaml) and I'm having an issue with overriding the OnMouseLeftButtonDown event in my control.
The way it is set up is this:
default grid holds 'PART_StackPanel'
which holds 1 column and 'Part_DateLabel'
Here's the xaml:
Code:
<ControlTemplate
x:Key="CtrlTemplate"
TargetType="ButtonBase">
<Border
x:Name="ContentContainer"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="1"
SnapsToDevicePixels="True">
<ContentPresenter
x:Name="Content"
RecognizesAccessKey="True"
Content="{TemplateBinding Content}"
ContentTemplate="{TemplateBinding ContentTemplate}"
ContentStringFormat="{TemplateBinding ContentStringFormat}"
Margin="{TemplateBinding Padding}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="UIElement.IsEnabled" Value="False">
<Setter Property="TextElement.Foreground">
<Setter.Value>
<DynamicResource ResourceKey="{x:Static SystemColors.GrayTextBrushKey}" />
</Setter.Value>
</Setter>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
<Style x:Key="{x:Type controls:CustomControl}" TargetType="{x:Type controls:CustomControl}">
<Setter Property="Width" Value="100"/>
<Setter Property="Height" Value="75"/>
<Setter Property="BorderBrush" Value="Black"/>
<Setter Property="BorderThickness" Value="0.25"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type controls:CustomControl}">
<Border
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
<Grid
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition/>
</Grid.RowDefinitions>
<StackPanel
x:Name="PART_StackPanel"
Orientation="Vertical"
VerticalAlignment="Stretch"
HorizontalAlignment="Stretch">
<Label
x:Name="PART_DateLabel"
Content="{TemplateBinding controls:CustomControl.LabelText}"
HorizontalContentAlignment="Right"
HorizontalAlignment="Stretch"/>
</StackPanel>
</Grid>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
The problem is that when I override the OnMouseLeftButtonDown event in the cs file like so:
Code:
protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
{
base.OnMouseLeftButtonDown(e);
MessageBox.Show("MouseDown fired");
}
However, the event is only called when the user clicks on the label at the top of the control. The rest of the control is empty and so the 'clickable' area of the control seems to only extend as far as the Label.
How can I set up the c# or xaml to call the OnMouseLeftButtonDown event throughout the entire control? Any ideas are much appreciated! Thanks!
Last edited by silentB4dawn; Feb 8th, 2011 at 09:54 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|