Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/xwt.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJérémie Laval <jeremie.laval@gmail.com>2018-07-18 18:34:01 +0300
committerGitHub <noreply@github.com>2018-07-18 18:34:01 +0300
commitb50afd198bc90d68f653e4704750ee64de55120b (patch)
treeb2c585d23d603dcb92b0cba17101f710d516948e
parentdba5955385d8d3c44cd5f38886fc94398619edea (diff)
parente097193a3db1828351c6cffbb3ba1aa252b979e5 (diff)
Merge pull request #842 from mono/remove-xaml-styles
[WPF] Convert XAML styles to code to avoid UI stalling
-rw-r--r--Xwt.WPF/Xwt.WPF.csproj5
-rw-r--r--Xwt.WPF/Xwt.WPFBackend/ButtonBackend.cs77
-rw-r--r--Xwt.WPF/Xwt.WPFBackend/Buttons.xaml56
3 files changed, 73 insertions, 65 deletions
diff --git a/Xwt.WPF/Xwt.WPF.csproj b/Xwt.WPF/Xwt.WPF.csproj
index a50361a0..719f015c 100644
--- a/Xwt.WPF/Xwt.WPF.csproj
+++ b/Xwt.WPF/Xwt.WPF.csproj
@@ -182,11 +182,6 @@
</Resource>
</ItemGroup>
<ItemGroup>
- <Resource Include="Xwt.WPFBackend\Buttons.xaml">
- <SubType>Designer</SubType>
- </Resource>
- </ItemGroup>
- <ItemGroup>
<EmbeddedResource Include="icons\add-16.png" />
<EmbeddedResource Include="icons\add-16~dark.png" />
<EmbeddedResource Include="icons\add-16~disabled.png" />
diff --git a/Xwt.WPF/Xwt.WPFBackend/ButtonBackend.cs b/Xwt.WPF/Xwt.WPFBackend/ButtonBackend.cs
index 3f1d1583..817cc12d 100644
--- a/Xwt.WPF/Xwt.WPFBackend/ButtonBackend.cs
+++ b/Xwt.WPF/Xwt.WPFBackend/ButtonBackend.cs
@@ -181,14 +181,83 @@ namespace Xwt.WPFBackend
{
get
{
- if (buttonsDictionary == null) {
- Uri uri = new Uri ("pack://application:,,,/Xwt.WPF;component/XWT.WPFBackend/Buttons.xaml");
- buttonsDictionary = (ResourceDictionary)XamlReader.Load (System.Windows.Application.GetResourceStream (uri).Stream);
- }
+ if (buttonsDictionary == null)
+ buttonsDictionary = CreateButtonResources ();
return buttonsDictionary;
}
}
+
+ static ResourceDictionary CreateButtonResources ()
+ {
+ // Toggle button template/style
+ var menuDropDownTemplate = new SWC.ControlTemplate (typeof (SWC.Primitives.ToggleButton));
+ menuDropDownTemplate.VisualTree = CreateButtonChromeFactory ();
+ var trigger = new Trigger { Property = SWC.Primitives.ToggleButton.IsKeyboardFocusedProperty, Value = true };
+ trigger.Setters.Add (new Setter (Microsoft.Windows.Themes.ButtonChrome.RenderDefaultedProperty, true, "Chrome"));
+ menuDropDownTemplate.Triggers.Add (trigger);
+ trigger = new Trigger { Property = SWC.Primitives.ToggleButton.IsCheckedProperty, Value = true };
+ trigger.Setters.Add (new Setter (Microsoft.Windows.Themes.ButtonChrome.RenderDefaultedProperty, true, "Chrome"));
+ menuDropDownTemplate.Triggers.Add (trigger);
+ trigger = new Trigger { Property = SWC.Primitives.ToggleButton.IsEnabledProperty, Value = false };
+ trigger.Setters.Add (new Setter (SWC.Primitives.ToggleButton.ForegroundProperty, new System.Windows.Media.SolidColorBrush (System.Windows.Media.Color.FromArgb (0xFF, 0xAD, 0xAD, 0xAD))));
+ menuDropDownTemplate.Triggers.Add (trigger);
+ var menuDropDownStyle = new Style (typeof (SWC.Primitives.ToggleButton));
+ menuDropDownStyle.Setters.Add (new Setter () {
+ Property = SWC.Control.TemplateProperty,
+ Value = menuDropDownTemplate
+ });
+
+ // Button template/style
+ var normalDropDownTemplate = new SWC.ControlTemplate (typeof (SWC.Button));
+ normalDropDownTemplate.VisualTree = CreateButtonChromeFactory ();
+ trigger = new Trigger { Property = SWC.Button.IsKeyboardFocusedProperty, Value = true };
+ trigger.Setters.Add (new Setter (Microsoft.Windows.Themes.ButtonChrome.RenderDefaultedProperty, true, "Chrome"));
+ normalDropDownTemplate.Triggers.Add (trigger);
+ trigger = new Trigger { Property = SWC.Button.IsEnabledProperty, Value = false };
+ trigger.Setters.Add (new Setter (SWC.Button.ForegroundProperty, new System.Windows.Media.SolidColorBrush (System.Windows.Media.Color.FromArgb (0xFF, 0xAD, 0xAD, 0xAD))));
+ normalDropDownTemplate.Triggers.Add (trigger);
+ var normalDropDownStyle = new Style (typeof (SWC.Button));
+ normalDropDownStyle.Setters.Add (new Setter () {
+ Property = SWC.Control.TemplateProperty,
+ Value = normalDropDownTemplate
+ });
+
+ menuDropDownStyle.Seal ();
+ normalDropDownStyle.Seal ();
+
+ var resourceDic = new ResourceDictionary ();
+ resourceDic.Add ("MenuDropDown", menuDropDownStyle);
+ resourceDic.Add ("NormalDropDown", normalDropDownStyle);
+
+ return resourceDic;
+ }
+
+ static FrameworkElementFactory CreateButtonChromeFactory ()
+ {
+ var panel = new FrameworkElementFactory (typeof (SWC.DockPanel));
+ var contentPresenter = new FrameworkElementFactory (typeof (SWC.ContentPresenter));
+ contentPresenter.SetValue (SWC.ContentPresenter.MarginProperty, new Thickness (2, 1, 0, 0));
+ panel.AppendChild (contentPresenter);
+ var path = new FrameworkElementFactory (typeof (System.Windows.Shapes.Path));
+ path.SetValue (System.Windows.Shapes.Path.DataProperty, Geometry.Parse ("M 0 0 L 3.5 4 L 7 0 Z"));
+ path.SetValue (System.Windows.Shapes.Path.FillProperty, Brushes.Black);
+ path.SetValue (System.Windows.Shapes.Path.HorizontalAlignmentProperty, HorizontalAlignment.Right);
+ path.SetValue (System.Windows.Shapes.Path.VerticalAlignmentProperty, VerticalAlignment.Center);
+ path.SetValue (System.Windows.Shapes.Path.MarginProperty, new Thickness (3, 1, 3, 0));
+ path.SetValue (SWC.DockPanel.DockProperty, SWC.Dock.Right);
+ panel.AppendChild (path);
+ var buttonChromeFactory = new FrameworkElementFactory (typeof (Microsoft.Windows.Themes.ButtonChrome));
+ buttonChromeFactory.SetBinding (Microsoft.Windows.Themes.ButtonChrome.BorderBrushProperty, new Binding ("BorderBrush") { RelativeSource = RelativeSource.TemplatedParent });
+ buttonChromeFactory.SetBinding (Microsoft.Windows.Themes.ButtonChrome.BackgroundProperty, new Binding ("Background") { RelativeSource = RelativeSource.TemplatedParent });
+ buttonChromeFactory.SetBinding (Microsoft.Windows.Themes.ButtonChrome.RenderMouseOverProperty, new Binding ("IsMouseOver") { RelativeSource = RelativeSource.TemplatedParent });
+ buttonChromeFactory.SetBinding (Microsoft.Windows.Themes.ButtonChrome.RenderPressedProperty, new Binding ("IsPressed") { RelativeSource = RelativeSource.TemplatedParent });
+ buttonChromeFactory.SetBinding (Microsoft.Windows.Themes.ButtonChrome.RenderDefaultedProperty, new Binding ("Button.IsDefaulted") { RelativeSource = RelativeSource.TemplatedParent });
+ buttonChromeFactory.SetValue (Microsoft.Windows.Themes.ButtonChrome.SnapsToDevicePixelsProperty, true);
+ buttonChromeFactory.Name = "Chrome";
+
+ return buttonChromeFactory;
+ }
}
class WpfButton : SWC.Button, IWpfWidget
diff --git a/Xwt.WPF/Xwt.WPFBackend/Buttons.xaml b/Xwt.WPF/Xwt.WPFBackend/Buttons.xaml
deleted file mode 100644
index 16c06b28..00000000
--- a/Xwt.WPF/Xwt.WPFBackend/Buttons.xaml
+++ /dev/null
@@ -1,56 +0,0 @@
-<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
- xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
- xmlns:l="clr-namespace:Xwt.WPFBackend;assembly=Xwt.WPF"
- xmlns:aero="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero">
-
- <Geometry x:Key="DownArrow">M 0 0 L 3.5 4 L 7 0 Z</Geometry>
-
- <Style x:Key="MenuDropDown" TargetType="ToggleButton">
- <Setter Property="Template">
- <Setter.Value>
- <ControlTemplate TargetType="{x:Type ToggleButton}">
- <aero:ButtonChrome x:Name="Chrome" BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}" RenderMouseOver="{TemplateBinding IsMouseOver}" RenderPressed="{TemplateBinding IsPressed}" RenderDefaulted="{TemplateBinding Button.IsDefaulted}" SnapsToDevicePixels="true">
- <DockPanel>
- <ContentPresenter Margin="2,1,0,0" />
- <Path DockPanel.Dock="Right" Data="{StaticResource DownArrow}" Fill="Black" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="3,1,3,0" />
- </DockPanel>
- </aero:ButtonChrome>
- <ControlTemplate.Triggers>
- <Trigger Property="IsKeyboardFocused" Value="true">
- <Setter Property="RenderDefaulted" TargetName="Chrome" Value="true"/>
- </Trigger>
- <Trigger Property="IsChecked" Value="true">
- <Setter Property="RenderPressed" TargetName="Chrome" Value="true"/>
- </Trigger>
- <Trigger Property="IsEnabled" Value="false">
- <Setter Property="Foreground" Value="#ADADAD"/>
- </Trigger>
- </ControlTemplate.Triggers>
- </ControlTemplate>
- </Setter.Value>
- </Setter>
- </Style>
-
- <Style x:Key="NormalDropDown" TargetType="Button">
- <Setter Property="Template">
- <Setter.Value>
- <ControlTemplate TargetType="{x:Type Button}">
- <aero:ButtonChrome x:Name="Chrome" BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}" RenderMouseOver="{TemplateBinding IsMouseOver}" RenderPressed="{TemplateBinding IsPressed}" RenderDefaulted="{TemplateBinding Button.IsDefaulted}" SnapsToDevicePixels="true">
- <DockPanel>
- <ContentPresenter Margin="2,1,0,0" />
- <Path DockPanel.Dock="Right" Data="{StaticResource DownArrow}" Fill="Black" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="3,1,3,0" />
- </DockPanel>
- </aero:ButtonChrome>
- <ControlTemplate.Triggers>
- <Trigger Property="IsKeyboardFocused" Value="true">
- <Setter Property="RenderDefaulted" TargetName="Chrome" Value="true"/>
- </Trigger>
- <Trigger Property="IsEnabled" Value="false">
- <Setter Property="Foreground" Value="#ADADAD"/>
- </Trigger>
- </ControlTemplate.Triggers>
- </ControlTemplate>
- </Setter.Value>
- </Setter>
- </Style>
-</ResourceDictionary> \ No newline at end of file