Advertisement
Guest User

Untitled

a guest
Dec 22nd, 2021
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.94 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.ComponentModel.DataAnnotations;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Windows;
  9. using System.Windows.Input;
  10. using System.Windows.Media;
  11. using System.Windows.Controls;
  12. using System.Xml.Serialization;
  13. using NinjaTrader.Cbi;
  14. using NinjaTrader.Gui;
  15. using NinjaTrader.Gui.Chart;
  16. using NinjaTrader.Gui.SuperDom;
  17. using NinjaTrader.Data;
  18. using NinjaTrader.NinjaScript;
  19. using NinjaTrader.Core.FloatingPoint;
  20. using NinjaTrader.NinjaScript.Indicators;
  21. using NinjaTrader.NinjaScript.DrawingTools;
  22.  
  23. namespace NinjaTrader.NinjaScript.AddOns
  24. {
  25.     public class TestWPFWindowSelector : System.Windows.Controls.WpfPropertyGrid.PropertyEditor
  26.     {
  27.         public TestWPFWindowSelector()
  28.         {
  29.             InlineTemplate = CreateTemplate();
  30.         }
  31.  
  32.         System.Windows.DataTemplate CreateTemplate()
  33.         {
  34.             const string xamlTemplate = @"
  35.             <DataTemplate >
  36.                   <Grid>
  37.                     <Grid.ColumnDefinitions>
  38.                       <ColumnDefinition Width=""30""/>
  39.                       <ColumnDefinition Width=""*""/>
  40.                     </Grid.ColumnDefinitions>
  41.              
  42.                 <Button Grid.Column=""0"" Content=""..."" Padding=""0"" Margin=""0""
  43.                           HorizontalAlignment=""Stretch"" VerticalAlignment=""Stretch""
  44.                           HorizontalContentAlignment=""Center""
  45.                           Style=""{x:Null}""
  46.                           Command =""pg:PropertyEditorCommands.ShowDialogEditor""
  47.                           CommandParameter=""{Binding}"" />
  48.              
  49.                     <TextBox Grid.Column=""1""
  50.                              Text=""{Binding StringValue}""
  51.                              ToolTip=""{Binding Value}""/>
  52.              
  53.                  
  54.                   </Grid>
  55.                 </DataTemplate>
  56.             ";
  57.  
  58.             System.Windows.Markup.ParserContext context = new System.Windows.Markup.ParserContext();
  59.             context.XmlnsDictionary.Add("", "http://schemas.microsoft.com/winfx/2006/xaml/presentation");
  60.             context.XmlnsDictionary.Add("x", "http://schemas.microsoft.com/winfx/2006/xaml");
  61.             context.XmlnsDictionary.Add("pg", "http://schemas.denisvuyka.wordpress.com/wpfpropertygrid");
  62.             System.Windows.DataTemplate template = (System.Windows.DataTemplate)System.Windows.Markup.XamlReader.Parse(xamlTemplate, context);
  63.             return template;
  64.         }
  65.  
  66.         public override void ClearValue(System.Windows.Controls.WpfPropertyGrid.PropertyItemValue propertyValue, System.Windows.IInputElement commandSource)
  67.         {
  68.             if (propertyValue == null || propertyValue.IsReadOnly)
  69.             {
  70.                 return;
  71.             }
  72.             propertyValue.StringValue = string.Empty;
  73.         }
  74.  
  75.         public override void ShowDialog(System.Windows.Controls.WpfPropertyGrid.PropertyItemValue propertyValue, System.Windows.IInputElement commandSource)
  76.         {
  77.             System.Windows.Controls.WpfPropertyGrid.PropertyGrid propGrid = commandSource as System.Windows.Controls.WpfPropertyGrid.PropertyGrid;
  78.             if (propGrid == null) return;
  79.  
  80.             NinjaTrader.Gui.Tools.NTWindow myWindow = new NinjaTrader.Gui.Tools.NTWindow();
  81.             myWindow.Width = 100;
  82.             myWindow.Height = 100;
  83.             myWindow.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterOwner;
  84.             bool? result = myWindow.ShowDialog();
  85.             propertyValue.StringValue = "success"; // change this string and compile, the ui does not see this change
  86.             propGrid.DoReload();
  87.             propGrid.RaiseEvent(new System.Windows.Controls.WpfPropertyGrid.PropertyValueChangedEventArgs(System.Windows.Controls.WpfPropertyGrid.PropertyGrid.PropertyValueChangedEvent, propertyValue.ParentProperty, ""));
  88.         }
  89.     }
  90. }
  91.  
  92.  
  93. //Use in a script:
  94. [Display(Name = "TestProperty", GroupName = "Test")]
  95. [PropertyEditor("NinjaTrader.NinjaScript.AddOns.TestWPFWindowSelector")]
  96. public string TestProperty { get; set; }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement