I'm building a Custom Control. Added an event to the xaml. Compiler complained, I added an x:Class entry. Then it complained that my class needed a partial verb. And now it's complaining: "Partial declarations of 'DigitTextBox' must not specify different base classes"
<ResourceDictionary
xmlns=";
xmlns:x=";
x:Class="DigitEntryControl.DigitTextBox"
xmlns:local="clr-namespace:DigitEntryControl">
<ControlTemplate x:Key="DigitMode" TargetType="{x:Type local:DigitTextBox}">
<Border Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
<Canvas PreviewKeyDown="DigitBox_PreviewKeyDown">
<TextBlock Text="{Binding SolidText}" HorizontalAlignment="Center" VerticalAlignment="Center" />
</Canvas>
</Border>
</ControlTemplate>
<ControlTemplate x:Key="HintMode" TargetType="{x:Type local:DigitTextBox}">
<Border Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
<UniformGrid Visibility="{Binding TriSelect}" Columns="3" PreviewKeyDown="DigitBox_PreviewKeyDown">
<TextBlock Text="1"/>
<TextBlock Text="2"/>
<TextBlock Text="3"/>
<TextBlock Text="4"/>
<TextBlock Text="5"/>
<TextBlock Text="6"/>
<TextBlock Text="7"/>
<TextBlock Text="8"/>
<TextBlock Text="9"/>
</UniformGrid>
</Border>
</ControlTemplate>
<Style TargetType="{x:Type local:DigitTextBox}">
<Setter Property="Template" Value="{StaticResource HintMode}"/>
<Style.Triggers>
<Trigger Property="IsHintMode" Value="false">
<Setter Property="Template" Value="{StaticResource DigitMode}"/>
</Trigger>
</Style.Triggers>
</Style>
</ResourceDictionary>
The full CS file is a bit long I've only included parts I thought were relevant.
namespace DigitEntryControl
{
public partial class DigitTextBox : Control, INotifyPropertyChanged
{
static DigitTextBox()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(DigitTextBox), new FrameworkPropertyMetadata(typeof(DigitTextBox)));
BackgroundProperty.OverrideMetadata(typeof(DigitTextBox), new FrameworkPropertyMetadata(Brushes.White));
BorderBrushProperty.OverrideMetadata(typeof(DigitTextBox), new FrameworkPropertyMetadata(Brushes.Black));
BorderThicknessProperty.OverrideMetadata(typeof(DigitTextBox), new FrameworkPropertyMetadata(new Thickness(0.5)));
WidthProperty.OverrideMetadata(typeof(DigitTextBox), new FrameworkPropertyMetadata(propertyChangedCallback: HeightWidthPropertyChanged));
HeightProperty.OverrideMetadata(typeof(DigitTextBox), new FrameworkPropertyMetadata(propertyChangedCallback: HeightWidthPropertyChanged));
}
}
}
The other answers for this type of error mostly deal with creating a UserControl. I tried applying the changes suggested for a UserControl, just more errors.
I'm building a Custom Control. Added an event to the xaml. Compiler complained, I added an x:Class entry. Then it complained that my class needed a partial verb. And now it's complaining: "Partial declarations of 'DigitTextBox' must not specify different base classes"
<ResourceDictionary
xmlns="http://schemas.microsoft/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft/winfx/2006/xaml"
x:Class="DigitEntryControl.DigitTextBox"
xmlns:local="clr-namespace:DigitEntryControl">
<ControlTemplate x:Key="DigitMode" TargetType="{x:Type local:DigitTextBox}">
<Border Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
<Canvas PreviewKeyDown="DigitBox_PreviewKeyDown">
<TextBlock Text="{Binding SolidText}" HorizontalAlignment="Center" VerticalAlignment="Center" />
</Canvas>
</Border>
</ControlTemplate>
<ControlTemplate x:Key="HintMode" TargetType="{x:Type local:DigitTextBox}">
<Border Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
<UniformGrid Visibility="{Binding TriSelect}" Columns="3" PreviewKeyDown="DigitBox_PreviewKeyDown">
<TextBlock Text="1"/>
<TextBlock Text="2"/>
<TextBlock Text="3"/>
<TextBlock Text="4"/>
<TextBlock Text="5"/>
<TextBlock Text="6"/>
<TextBlock Text="7"/>
<TextBlock Text="8"/>
<TextBlock Text="9"/>
</UniformGrid>
</Border>
</ControlTemplate>
<Style TargetType="{x:Type local:DigitTextBox}">
<Setter Property="Template" Value="{StaticResource HintMode}"/>
<Style.Triggers>
<Trigger Property="IsHintMode" Value="false">
<Setter Property="Template" Value="{StaticResource DigitMode}"/>
</Trigger>
</Style.Triggers>
</Style>
</ResourceDictionary>
The full CS file is a bit long I've only included parts I thought were relevant.
namespace DigitEntryControl
{
public partial class DigitTextBox : Control, INotifyPropertyChanged
{
static DigitTextBox()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(DigitTextBox), new FrameworkPropertyMetadata(typeof(DigitTextBox)));
BackgroundProperty.OverrideMetadata(typeof(DigitTextBox), new FrameworkPropertyMetadata(Brushes.White));
BorderBrushProperty.OverrideMetadata(typeof(DigitTextBox), new FrameworkPropertyMetadata(Brushes.Black));
BorderThicknessProperty.OverrideMetadata(typeof(DigitTextBox), new FrameworkPropertyMetadata(new Thickness(0.5)));
WidthProperty.OverrideMetadata(typeof(DigitTextBox), new FrameworkPropertyMetadata(propertyChangedCallback: HeightWidthPropertyChanged));
HeightProperty.OverrideMetadata(typeof(DigitTextBox), new FrameworkPropertyMetadata(propertyChangedCallback: HeightWidthPropertyChanged));
}
}
}
The other answers for this type of error mostly deal with creating a UserControl. I tried applying the changes suggested for a UserControl, just more errors.
Share asked Mar 6 at 20:40 NottocNottoc 1037 bronze badges 4 |1 Answer
Reset to default 0Instead of attaching an event handler in a ControlTemplate in the default control Style, you can attach an event handler in code behind in the OnApplyTemplate method, e.g. as shown here: How to get events handlers for custom controls in Generic.Xaml
Themes\Generic.xaml
. There you do not add anx:Class
declaration, and you do not specifypartial
on a custom control class. Please clarify what the original problem was. You may want to attach the event handler in code, as shown here: stackoverflow/q/23610581/1136211 – Clemens Commented Mar 7 at 7:45