<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:t="clr-namespace:NinjaTrader.Gui.Tools;assembly=NinjaTrad er.Gui"
xmlns:sys="clr-namespace:System;assembly=mscorlib">
<Page.Resources>
<!-- Make sure this namespace is declared so that it's in scope below -->
<ObjectDataProvider MethodName="GetType"
ObjectType="{x:Type sys:Type}" x:Key="colorsTypeOdp">
<ObjectDataProvider.MethodParameters>
<sys:String>System.Windows.Media.Colors, PresentationCore,
Version=3.0.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35</sys:String>
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
<ObjectDataProvider ObjectInstance="{StaticResource colorsTypeOdp}"
MethodName="GetProperties" x:Key="colorPropertiesOdp">
</ObjectDataProvider>
</Page.Resources>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="15" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="15" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="10" />
<RowDefinition Height="25" />
<RowDefinition Height="28" />
<RowDefinition Height="25" />
<RowDefinition Height="28" />
<RowDefinition Height="25" />
<RowDefinition Height="28" />
<RowDefinition Height="30" />
<RowDefinition Height="28" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Label Grid.Column="1" Grid.Row="1" Content="Set Instrument" Foreground="#CCCCCC" HorizontalAlignment="Left" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" VerticalAlignment="Top "/>
<t:InstrumentSelector x:Name="InstrumentSelectorInput" Grid.Row="2" Grid.Column="1" LastUsedGroup="SetIndicatorValueFromAddonExample" VerticalAlignment="Top">
<t:InstrumentSelector.Margin>
<Thickness Left="{StaticResource MarginBase}" Top="{StaticResource PaddingColumn}" Bottom="0 "/>
</t:InstrumentSelector.Margin>
</t:InstrumentSelector>
<Label Grid.Column="1" Grid.Row="3" Content="Set integer value" HorizontalAlignment="Left" VerticalAlignment="Top" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" Foreground="#CCCCCC" />
<t:QuantityUpDown x:Name="QuantityUpDownInput" Grid.Row="4" Grid.Column="1" Value="1">
<t:QuantityUpDown.Margin>
<Thickness Left="{StaticResource MarginBase}" Top="{StaticResource MarginControl}" Bottom="0" />
</t:QuantityUpDown.Margin>
</t:QuantityUpDown>
<Label Grid.Column="1" Grid.Row="5" Content="Set string value" HorizontalAlignment="Left" VerticalAlignment="Top" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" Foreground="#CCCCCC" />
<TextBox x:Name="StringValueInput" Grid.Column="1" Grid.Row="6" Text="Sample Text" VerticalAlignment="Top">
<TextBox.Margin>
<Thickness Left="{StaticResource MarginBase}" Top="{StaticResource MarginControl}" Bottom="0" />
</TextBox.Margin>
</TextBox>
<ComboBox Name="BrushComboBox" Grid.Row="7" Grid.Column="1"
ItemsSource="{Binding Source={StaticResource colorPropertiesOdp}}"
SelectedValuePath="Name">
<ComboBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Height="18" Margin="0,0,0,2">
<Border BorderThickness="1" CornerRadius="2"
BorderBrush="Black" Width="50" VerticalAlignment="Stretch"
Background="{Binding Name}"/>
<TextBlock Text="{Binding Name}" Margin="8,0,0,0"/>
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
<StackPanel Grid.Column="1" Grid.Row="8" HorizontalAlignment="Right" Orientation="Horizontal">
<Button x:Name="OkButton" Content="Ok" Width="50 "/>
<Button x:Name="CancelButton" Content="Cancel" Width="50 "/>
</StackPanel>
</Grid>
</Page>
and here the code:
public class IndicatorWindowDataManagementNTWindow : NTWindow
{
private Button cancelButton;
private InstrumentSelector instrumentSelectorInput;
private Instrument instrumentValue;
private Button okButton;
private QuantityUpDown quantityUpDownInput;
private TextBox stringValueInput;
private ComboBox combo;
private Brush brush;
public Indicators.SetIndicatorValueFromAddonWindowExample TargetIndicator;
public IndicatorWindowDataManagementNTWindow()
{
Caption = "IndicatorWindow Data Management Tools";
Width = 400;
Height = 250;
Height = 10050;
Loaded += OnWindow_Loaded;
Closing += OnWindow_Close;
}
private void OnWindow_Loaded(object sender, RoutedEventArgs e)
{
Content = LoadXaml();
}
private void OnWindow_Close(object sender, System.ComponentModel.CancelEventArgs e)
{
if (cancelButton != null)
cancelButton.Click -= OnCancelButton_Click;
if (instrumentSelectorInput != null)
instrumentSelectorInput.InstrumentChanged -= OnInstrument_Changed;
if (okButton != null)
okButton.Click -= OnOkButton_Click;
}
private DependencyObject LoadXaml()
{
Page page = new Page();
FileStream fs = new FileStream(System.IO.Path.Combine(NinjaTrader.Core .Globals.UserDataDir, @"bin\Custom\Xaml\SetIndicatorValueFromAddonWin dow ExampleToolsContent.xaml"), FileMode.Open);
page = (Page)XamlReader.Load(fs);
if (page == null)
return null;
cancelButton = LogicalTreeHelper.FindLogicalNode(page, "CancelButton") as Button;
if (cancelButton != null)
cancelButton.Click += OnCancelButton_Click;
okButton = LogicalTreeHelper.FindLogicalNode(page, "OkButton") as Button;
if (okButton != null)
okButton.Click += OnOkButton_Click;
instrumentSelectorInput = LogicalTreeHelper.FindLogicalNode(page, "InstrumentSelectorInput") as InstrumentSelector;
if (instrumentSelectorInput != null)
instrumentSelectorInput.InstrumentChanged += OnInstrument_Changed;
quantityUpDownInput = LogicalTreeHelper.FindLogicalNode(page, "QuantityUpDownInput") as QuantityUpDown;
stringValueInput = LogicalTreeHelper.FindLogicalNode(page, "StringValueInput") as TextBox;
combo = LogicalTreeHelper.FindLogicalNode(page, "BrushComboBox") as ComboBox;
if (combo != null)
combo.SelectionChanged += OnSelectionChanged;
DependencyObject pageContent = page.Content as DependencyObject;
return pageContent;
}
private void OnSelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (TargetIndicator == null)
return;
}
private void OnCancelButton_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
private void OnInstrument_Changed(object sender, EventArgs e)
{
instrumentValue = sender as Cbi.Instrument;
brush = combo.SelectedItem as Brush;
}
private void OnOkButton_Click(object sender, RoutedEventArgs e)
{
if (TargetIndicator == null)
return;
if (instrumentValue != null)
TargetIndicator.InstrumentValue = instrumentValue;
if (quantityUpDownInput != null)
TargetIndicator.IntValue = quantityUpDownInput.Value;
if (stringValueInput != null)
TargetIndicator.StringValue = stringValueInput.Text;
if (combo != null)
TargetIndicator.MyBrush = brush;
TargetIndicator.ShowValues();
this.Close();
}
}
I can't figure out where is the problem with the code.
Comment