Trouble porting a custom Button from WPF to Noesis
Posted: 03 Aug 2019, 20:31
I have a custom Button defined in "StandardToggleButton.xaml" (abbreviated):
The code-behind StandardToggleButton.xaml.cs
Used like this in MainWindow.xaml:
Minimal example attached.
Code: Select all
<Button x:Class="ButtonTest.StandardToggleButton"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:ButtonTest"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d">
<Button.Resources>
<Color x:Key="GridForegroundOnColor">#EDEEEF</Color>
<Color x:Key="GridBackgroundOnColor">#3B73B9</Color>
<Color x:Key="GridForegroundOffColor">#5C5F63</Color>
<Color x:Key="GridBackgroundOffColor">#313337</Color>
<ControlTemplate x:Key="{ComponentResourceKey TypeInTargetAssembly=
local:StandardToggleButton, ResourceId=StandardToggleButtonControlTemplate}"
TargetType="{x:Type local:StandardToggleButton}">
...
</ControlTemplate>
<Style TargetType="{x:Type local:StandardToggleButton}">
<Setter Property="Template"
Value="{StaticResource {ComponentResourceKey
TypeInTargetAssembly=local:StandardToggleButton,
ResourceId=StandardToggleButtonControlTemplate}}" />
</Style>
</Button.Resources>
</Button>
Code: Select all
#if USE_WPF
using System.Windows;
using System.Windows.Controls;
#else
using Noesis;
#endif
namespace ButtonTest
{
public partial class StandardToggleButton : Button
{
/// <summary>
/// The constructor.
/// </summary>
public StandardToggleButton()
{
InitializeComponent();
}
public static readonly DependencyProperty IsOnProperty = DependencyProperty.Register("IsOn", typeof(bool), typeof(StandardToggleButton), new FrameworkPropertyMetadata());
public bool IsOn
{
get
{
return (bool)GetValue(IsOnProperty);
}
set
{
SetValue(IsOnProperty, value);
}
}
#if !USE_WPF
private void InitializeComponent()
{
GUI.LoadComponent(this, "StandardButtonControl.xaml");
}
#endif
}
}
Code: Select all
<Window x:Class="ButtonTest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:ButtonTest"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
<local:StandardToggleButton></local:StandardToggleButton>
</Grid>
</Window>