Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace NinjaTrader.NinjaScript.AddOns
- {
- public class TestWPFWindowSelector : System.Windows.Controls.WpfPropertyGrid.PropertyEditor
- {
- public TestWPFWindowSelector()
- {
- InlineTemplate = CreateTemplate();
- }
- System.Windows.DataTemplate CreateTemplate()
- {
- const string xamlTemplate = @"
- <DataTemplate >
- <Grid>
- <Grid.ColumnDefinitions>
- <ColumnDefinition Width=""30""/>
- <ColumnDefinition Width=""*""/>
- </Grid.ColumnDefinitions>
- <Button Grid.Column=""0"" Content=""..."" Padding=""0"" Margin=""0""
- HorizontalAlignment=""Stretch"" VerticalAlignment=""Stretch""
- HorizontalContentAlignment=""Center""
- Style=""{x:Null}""
- Command =""pg:PropertyEditorCommands.ShowDialogEditor""
- CommandParameter=""{Binding}"" />
- <TextBox Grid.Column=""1""
- Text=""{Binding StringValue}""
- ToolTip=""{Binding Value}""/>
- </Grid>
- </DataTemplate>
- ";
- System.Windows.Markup.ParserContext context = new System.Windows.Markup.ParserContext();
- context.XmlnsDictionary.Add("", "http://schemas.microsoft.com/winfx/2006/xaml/presentation");
- context.XmlnsDictionary.Add("x", "http://schemas.microsoft.com/winfx/2006/xaml");
- context.XmlnsDictionary.Add("pg", "http://schemas.denisvuyka.wordpress.com/wpfpropertygrid");
- System.Windows.DataTemplate template = (System.Windows.DataTemplate)System.Windows.Markup.XamlReader.Parse(xamlTemplate, context);
- return template;
- }
- public override void ClearValue(System.Windows.Controls.WpfPropertyGrid.PropertyItemValue propertyValue, System.Windows.IInputElement commandSource)
- {
- if (propertyValue == null || propertyValue.IsReadOnly)
- {
- return;
- }
- propertyValue.StringValue = string.Empty;
- }
- public override void ShowDialog(System.Windows.Controls.WpfPropertyGrid.PropertyItemValue propertyValue, System.Windows.IInputElement commandSource)
- {
- System.Windows.Controls.WpfPropertyGrid.PropertyGrid propGrid = commandSource as System.Windows.Controls.WpfPropertyGrid.PropertyGrid;
- if (propGrid == null) return;
- NinjaTrader.Gui.Tools.NTWindow myWindow = new NinjaTrader.Gui.Tools.NTWindow();
- myWindow.Width = 100;
- myWindow.Height = 100;
- myWindow.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterOwner;
- bool? result = myWindow.ShowDialog();
- propertyValue.StringValue = "success"; // change this string and compile, the ui does not see this change
- propGrid.DoReload();
- propGrid.RaiseEvent(new System.Windows.Controls.WpfPropertyGrid.PropertyValueChangedEventArgs(System.Windows.Controls.WpfPropertyGrid.PropertyGrid.PropertyValueChangedEvent, propertyValue.ParentProperty, ""));
- }
- }
- }
- //*********************************************************************************************************************************
- Use in a script:
- [Display(Name = "TestProperty", GroupName = "Test")]
- [PropertyEditor("NinjaTrader.NinjaScript.AddOns.TestWPFWindowSelector")]
- public string TestProperty { get; set; }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement