0

i built a control template, with two buttons, which i use in the MainWindow Class:

The ControlTemplate:

<ControlTemplate x:Key="LeftPanelTemplate">
    <Grid  Grid.Column="0"  Grid.Row="0" Margin="10,15,5,5" >
        <Border BorderThickness="7" CornerRadius="4">
            <Border.BorderBrush>
                <SolidColorBrush Color="#73B2F5" Opacity="0.5"/>
            </Border.BorderBrush>
            <Grid>
                <Grid.Background>
                    <SolidColorBrush Color="#73B2F5" Opacity="0.5"/>
                </Grid.Background>
                <Grid.RowDefinitions>
                    <RowDefinition Height="30"/>
                    <RowDefinition Height="1*"/>
                </Grid.RowDefinitions>
                <Button Name="CustomerButton" Grid.Row="1" Grid.Column="0" Width="40" Height="40" Content="Customer" Click="CustTabButton_Click" ></Button>
                <Button Name="BossButton" Grid.Row="1" Width="40" Height="40" Content="Boss" Margin="23,206,23,114" Click="BossTabButton_Click"></Button>
            </Grid>
        </Border>
    </Grid>
</ControlTemplate>

I reference it at the MainWindow XAML:

<ContentControl Template="{StaticResource LeftPanelTemplate}"/>

i get an error that the click events of the two buttons inside the control template could not be found - because i moved it to the ResourceDirectory file called MainWindowResources.xaml:

'MyWPFApp.MainWindowResource' does not contain a definition for 'CustTabButton_Click' and no extension method 'CustTabButton_Click' accepting a first argument of type 'MyWPFApp.MainWindowResource' could be found (are you missing a using directive or an assembly reference?)

i found this link: Is it possible to set code behind a resource dictionary in WPF for event handling?

is there a shorter way for the click events in the MainWindow code behind to be executed from the resource Directory? because moving the whole code from the MainWindow to a REsourceDirectory.xaml.code can take alot of time and expose to public alot of variables.

Community
  • 1
  • 1
Rodniko
  • 4,926
  • 20
  • 69
  • 93

1 Answers1

1

you could use commands instead of button click and bind the commands from your mainwindow to the usercontrol.

blindmeis
  • 22,175
  • 7
  • 55
  • 74