private void toolBarButton_Enter(object sender, RoutedEventArgs e) { Print("enter"); Style toolBarStyle = new Style(); toolBarStyle.TargetType = typeof(System.Windows.Controls.Button); toolBarStyle.Setters.Add(new Setter(System.Windows.Controls.Button.FontSizeProperty, 11.0)); toolBarStyle.Setters.Add(new Setter(System.Windows.Controls.Button.BackgroundProperty, Brushes.Red)); toolBarStyle.Setters.Add(new Setter(System.Windows.Controls.Button.ForegroundProperty, new SolidColorBrush(Color.FromRgb(200,200,200)))); toolBarStyle.Setters.Add(new Setter(System.Windows.Controls.Button.FontFamilyProperty, new FontFamily("Courier New"))); toolBarStyle.Setters.Add(new Setter(System.Windows.Controls.Button.FontWeightProperty, FontWeights.Bold)); //Set Button Style toolBarButton.Style = toolBarStyle; }
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Buttons-StackPanels-DockPanels
Collapse
X
-
I'm attempting to change the style of a toolbar button when the mouse enters the toolbar button. I can manipulate the font and the font size, as well as the foreground color, but I can't override the background color. I'm pretty sure the code is fine (see below), but whenever I mouse over the toolbar button I'm stuck with the default highlighted color.
Code:
-
Hello TheBarChartist,
You need to override the default control template where the logic that handles the visual display of the button on mouse over events is stored. A good walkthrough is available on the msdn website here: https://msdn.microsoft.com/en-us/lib...(v=vs.95).aspx
A more specific article on the same can be found on stack overflow here: http://stackoverflow.com/questions/1...useover-in-wpf
Using XamlReader.Parse() you can setup custom xaml in your C# code as a string, and then parse it into a style or control template.
Please let me know if you have any questions or if I may be of further assistance.Michael M.NinjaTrader Quality Assurance
Comment
-
It was a long hard fight, but I figured out how to add the following code to the ControlTemplate of my button:
Code:</Trigger> <Trigger Property="IsMouseOver" Value="True"> <Setter Property="Background" Value="Red"/> </Trigger>
And I had success, in that now when I mouse over the button the background changes to red. But the problem is that it doesn't stay red. While the mouse is still over the button, it changes back to the default color.
Does anyone know what state my button is transitioning to while the mouse is hovering over it so that I can edit that property as well?
Comment
-
All that's left for me to do is some cosmetic work on my indicators, so I thought I would bump this.
Here's what I'm doing to access, modify, and then set the ControlTemplate for my button:
Code:XmlWriterSettings xmlSettings = new XmlWriterSettings(); xmlSettings.Indent = true; StringBuilder sb = new StringBuilder(); XmlWriter writer = XmlWriter.Create(XmlWriter.Create(sb, xmlSettings)); XamlWriter.Save(toolBarButton.Template, writer); Print(sb.ToString()); sb.Remove(sb.Length - 50, 50); sb.Append("\n\t<Trigger Property=\"IsMouseOver\" Value=\"True\">\n\t\t<Setter Property=\"Background\" Value=\"Red\"/>\n\t</Trigger>\n\t</ControlTemplate.Triggers>\n</ControlTemplate>"); toolBarButton.Template = (ControlTemplate)XamlReader.Parse(sb.ToString()); Print(sb.ToString());
Code:<?xml version="1.0" encoding="utf-16"?> <ControlTemplate TargetType="ButtonBase" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:mwt="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero"> <mwt:ButtonChrome Background="{TemplateBinding Panel.Background}" BorderBrush="{TemplateBinding Border.BorderBrush}" RenderDefaulted="{TemplateBinding Button.IsDefaulted}" RenderMouseOver="{TemplateBinding UIElement.IsMouseOver}" RenderPressed="{TemplateBinding ButtonBase.IsPressed}" Name="Chrome" SnapsToDevicePixels="True"> <ContentPresenter RecognizesAccessKey="True" Content="{TemplateBinding ContentControl.Content}" ContentTemplate="{TemplateBinding ContentControl.ContentTemplate}" ContentStringFormat="{TemplateBinding ContentControl.ContentStringFormat}" Margin="{TemplateBinding Control.Padding}" HorizontalAlignment="{TemplateBinding Control.HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding Control.VerticalContentAlignment}" SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" /> </mwt:ButtonChrome> <ControlTemplate.Triggers> <Trigger Property="UIElement.IsKeyboardFocused"> <Setter Property="mwt:ButtonChrome.RenderDefaulted" TargetName="Chrome"> <Setter.Value> <s:Boolean>True</s:Boolean> </Setter.Value> </Setter> <Trigger.Value> <s:Boolean>True</s:Boolean> </Trigger.Value> </Trigger> <Trigger Property="ToggleButton.IsChecked"> <Setter Property="mwt:ButtonChrome.RenderPressed" TargetName="Chrome"> <Setter.Value> <s:Boolean>True</s:Boolean> </Setter.Value> </Setter> <Trigger.Value> <s:Boolean>True</s:Boolean> </Trigger.Value> </Trigger> <Trigger Property="UIElement.IsEnabled"> <Setter Property="TextElement.Foreground"> <Setter.Value> <SolidColorBrush>#FFADADAD</SolidColorBrush> </Setter.Value> </Setter> <Trigger.Value> <s:Boolean>False</s:Boolean> </Trigger.Value> </Trigger> </ControlTemplate.Triggers> </ControlTemplate>
Code:<?xml version="1.0" encoding="utf-16"?> <ControlTemplate TargetType="ButtonBase" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:mwt="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero"> <mwt:ButtonChrome Background="{TemplateBinding Panel.Background}" BorderBrush="{TemplateBinding Border.BorderBrush}" RenderDefaulted="{TemplateBinding Button.IsDefaulted}" RenderMouseOver="{TemplateBinding UIElement.IsMouseOver}" RenderPressed="{TemplateBinding ButtonBase.IsPressed}" Name="Chrome" SnapsToDevicePixels="True"> <ContentPresenter RecognizesAccessKey="True" Content="{TemplateBinding ContentControl.Content}" ContentTemplate="{TemplateBinding ContentControl.ContentTemplate}" ContentStringFormat="{TemplateBinding ContentControl.ContentStringFormat}" Margin="{TemplateBinding Control.Padding}" HorizontalAlignment="{TemplateBinding Control.HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding Control.VerticalContentAlignment}" SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" /> </mwt:ButtonChrome> <ControlTemplate.Triggers> <Trigger Property="UIElement.IsKeyboardFocused"> <Setter Property="mwt:ButtonChrome.RenderDefaulted" TargetName="Chrome"> <Setter.Value> <s:Boolean>True</s:Boolean> </Setter.Value> </Setter> <Trigger.Value> <s:Boolean>True</s:Boolean> </Trigger.Value> </Trigger> <Trigger Property="ToggleButton.IsChecked"> <Setter Property="mwt:ButtonChrome.RenderPressed" TargetName="Chrome"> <Setter.Value> <s:Boolean>True</s:Boolean> </Setter.Value> </Setter> <Trigger.Value> <s:Boolean>True</s:Boolean> </Trigger.Value> </Trigger> <Trigger Property="UIElement.IsEnabled"> <Setter Property="TextElement.Foreground"> <Setter.Value> <SolidColorBrush>#FFADADAD</SolidColorBrush> </Setter.Value> </Setter> <Trigger.Value> <s:Boolean>False</s:Boolean> </Trigger.Value> </Trigger> <Trigger Property="IsMouseOver" Value="True"> <Setter Property="Background" Value="Red"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate>
It also puts an thin outline around the button. The style of the button seems changed in a subtle way.
Comment
-
Not following this topic for a while and now I see Edge has made a big progress with the charts he showed here. Congratulations!
One thing I notice is that the buttons are placed inside a chart, so they occupy some space of chart. This space may be important in some situations, so users may prefer the buttons placed in a separate toolbar, which can be put at top, left, right, bottom of chart (see the pic below). I mean a toolbar outside of chart, just like Chart Trader's behavior.
I know we will have to handle tab-sensitivity issue. But in some cases the toolbar can be global (for all tabs), just like the quick-drawing toolbar.
Any instructions on this?
Thanks.
Pi
Comment
-
Originally posted by ninZa View PostNot following this topic for a while and now I see Edge has made a big progress with the charts he showed here. Congratulations! One thing I notice is that the buttons are placed inside a chart, so they occupy some space of chart. This space may be important in some situations, so users may prefer the buttons placed in a separate toolbar, which can be put at top, left, right, bottom of chart (see the pic below). I mean a toolbar outside of chart, just like Chart Trader's behavior. Any instructions on this?
I do suggest that anyone utilizing this approach keep in mind that as time goes on, this UserControlCollection space is going to become a premium.. And that you should design your controls in mind that they might/will indeed share space with other indicators from various sources.. One way of doing this would be to use a user definable variable inside your controls margin, so that your users have control of what gets placed where..
Just an example of me allowing my users to drop their color palette below the drawbar, or visa versa, or even adjust it below any other controls they might be using if they so choose..
Comment
-
Originally posted by TheBarChartist View PostWhen I alter the ControlTemplate in this way, upon mouse over the button turns red for maybe half a second and then returns to the default mouse over color, even though the mouse is still over the button. It also puts an thin outline around the button. The style of the button seems changed in a subtle way.
Comment
-
Ninza,
We're working on a concept internally which should be available for next beta which would allow you to do this. You technically can go in and try messing with the visual tree but the chart does not adapt correctly to the new size and ends up with unexpected results. With the next beta this will be resolved so you could inject your own toolbar there.
The other piece of the puzzle is getting that data saved to the workspace. Which we are working on as well.
Please keep an eye out for that for the next beta and we likely would be adding documentation on how to do that as well shortly thereafter as long as we don't run into any blockers that would prevent us from doing so.
Comment
-
Originally posted by NinjaTrader_Brett View PostWe're working on a concept internally which should be available for next beta which would allow you to do this. You technically can go in and try messing with the visual tree but the chart does not adapt correctly to the new size and ends up with unexpected results. With the next beta this will be resolved so you could inject your own toolbar there.
Comment
-
Originally posted by NinjaTrader_Brett View PostNinza,
We're working on a concept internally which should be available for next beta which would allow you to do this. You technically can go in and try messing with the visual tree but the chart does not adapt correctly to the new size and ends up with unexpected results. With the next beta this will be resolved so you could inject your own toolbar there.
The other piece of the puzzle is getting that data saved to the workspace. Which we are working on as well.
Please keep an eye out for that for the next beta and we likely would be adding documentation on how to do that as well shortly thereafter as long as we don't run into any blockers that would prevent us from doing so.
We hope Beta 7 will be released at the end of this month or early December.
Comment
-
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by Yasharandom, Today, 07:45 AM
|
0 responses
4 views
0 likes
|
Last Post
by Yasharandom
Today, 07:45 AM
|
||
Started by llanqui, Yesterday, 09:59 AM
|
4 responses
23 views
0 likes
|
Last Post
by llanqui
Today, 07:22 AM
|
||
Started by smartromain, 03-13-2024, 01:42 AM
|
5 responses
95 views
0 likes
|
Last Post
by AndreiBig
Today, 06:08 AM
|
||
Started by Noerclou, Today, 04:55 AM
|
0 responses
5 views
0 likes
|
Last Post
by Noerclou
Today, 04:55 AM
|
||
Started by ThoriSten, Today, 03:56 AM
|
0 responses
6 views
0 likes
|
Last Post
by ThoriSten
Today, 03:56 AM
|
Comment