Advertisement
Guest User

Untitled

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