Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to access resource from xaml file

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    How to access resource from xaml file

    Hello

    I have created an Addon and I need to access an image from my xaml and C# code.

    I have created a folder under Documents\NinjaTrader 8\templates folder called MyResources where I have put my images.

    Now from my xaml code I get an error. It is not finding the ressource.

    My xaml file is located under the AddOns folder.

    Here is the xaml code I use :

    <Setter Property="Source" Value="MyResources/NT Button Off.png" />

    What is the right path I should use ?

    Thank you
    Last edited by blar58; 12-01-2022, 02:26 PM.

    #2
    Hello blar58,

    Thanks for your post.

    NinjaTrader does not compile XAML so you would not be able to use images in XAML like you shared.

    This would need to be accomplished similarly to the AddOn Framework linked below. Create controls in XAML and then use C# code to manipulate the controls. You would need to load the image from file and then set it as an image controls image.

    AddOn Framework / AddOn Development overview: https://ninjatrader.com/support/help...t_overview.htm
    Creating your own AddOn window: https://ninjatrader.com/support/help...don_window.htm

    If possible, you could consider not using an image and instead use a path geometry which could be included as code in the XAML as a resource.

    You could find an example posted by my colleague Jesse in this forum thread: https://ninjatrader.com/support/foru...584#post719584

    Please let me know if I may assist further.
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment


      #3
      Brandon

      Could you just help me to set that image to my control.

      Here is the xaml control :

      <DataGrid Name="McDataGrid" AutoGenerateColumns="False" CanUserAddRows="False" Margin="5,5,0,0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Height="Auto" MinHeight="50" BorderThickness="1" HorizontalGridLinesBrush="White" VerticalGridLinesBrush="White"
      ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Auto" Grid.Row="1">
      <DataGrid.Columns>
      <DataGridCheckBoxColumn Header="On" Width="Auto" Binding="{Binding Path=On,Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />​
      </DataGrid.Columns>
      </DataGrid>


      In my code :

      McDataGrid = LogicalTreeHelper.FindLogicalNode(pageContent, "McDataGrid") as DataGrid;
      McDataGrid.ItemsSource = MyListObjects;

      Now in that DataGridCheckBoxColumn I would like to change the checkbox by a button image which is gray when not selected and green when selected.
      I have two button images ButtonOn and ButtonOff.

      How do I set the images to this Data Grid Checkbox Column from code ?

      Any help would be greatly appreciated !
      ​​

      Comment


        #4
        Hello blar58,

        Thanks for your note.

        This would go beyond the support we would be able to provide in the Support department at NinjaTrader.

        This would be considered working with WPF controls and not NinjaScript-specific code. To accomplish your goal you would need to look up how to do that with the WPF control that you are using.

        Here is a publicly available MSDN page with information about working with WPF controls which you might find helpful: https://learn.microsoft.com/en-us/do.../wpf/controls/

        Let me know if you have further questions.

        <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        633 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        364 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        105 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        567 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        568 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X