- darthmaule2
- Posts: 98
- Joined:
Trouble porting a custom Button from WPF to Noesis
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>
- darthmaule2
- Posts: 98
- Joined:
Re: Trouble porting a custom Button from WPF to Noesis
Looks like I'm not able to attach files - not sure what the issue is. I tried all three browsers and via drag and drop and the "Add files" button.
-
sfernandez
Site Admin
- Posts: 2984
- Joined:
Re: Trouble porting a custom Button from WPF to Noesis
Hello,
Noesis doesn't implement ComponentResourceKey, the xaml parser should be logging that as an error like:
Noesis doesn't implement ComponentResourceKey, the xaml parser should be logging that as an error like:
But you can use string keys in this case and it works as expected:[noesis] StandardToggleButton.xaml(11): Can't set an extension of type 'ComponentResourceKey' as Key
Code: Select all
<ControlTemplate x:Key="StandardToggleButtonTemplate" TargetType="{x:Type local:StandardToggleButton}">
...
</ControlTemplate>
<Style TargetType="{x:Type local:StandardToggleButton}">
<Setter Property="Template" Value="{StaticResource StandardToggleButtonTemplate}" />
</Style>
- darthmaule2
- Posts: 98
- Joined:
Re: Trouble porting a custom Button from WPF to Noesis
That fixed it, thanks.
You mention the XamlPlayer... is there a standard way to integrate Noesis Xaml parsing output into a build? My current setup provides no debug output on Xaml parsing which makes it very difficult to debug Xaml issues. I can drag & drop a xaml into the XamlPlayer, but it would be nice if my build output just displayed whatever parsing errors occurred... right now it just seems to fail silently.
You mention the XamlPlayer... is there a standard way to integrate Noesis Xaml parsing output into a build? My current setup provides no debug output on Xaml parsing which makes it very difficult to debug Xaml issues. I can drag & drop a xaml into the XamlPlayer, but it would be nice if my build output just displayed whatever parsing errors occurred... right now it just seems to fail silently.
-
sfernandez
Site Admin
- Posts: 2984
- Joined:
Re: Trouble porting a custom Button from WPF to Noesis
By default we were logging all that information to the debugger Output window, unfortunately I just found that it was only working for the debug version of the library (we were using System.Diagnostics.Debug.WriteLine), so it was in fact useless if user didn't build their own debug version of Noesis.App package.
We decided to add support in Application class to override how logs and unhandled exceptions are managed in next release:
By default these functions will use Console.WriteLine() to output the log message and the exception.
We decided to add support in Application class to override how logs and unhandled exceptions are managed in next release:
Code: Select all
public class App : Application
{
...
protected override void OnLog(LogLevel level, string channel, string message) { ... }
protected override void OnUnhandledException(Exception e) { ... }
}
Who is online
Users browsing this forum: Bing [Bot], Google [Bot] and 79 guests