Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6847437
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:44:41+00:00 2026-05-27T00:44:41+00:00

We have some XAML which may seem odd but apparently is needed for defining

  • 0

We have some XAML which may seem odd but apparently is needed for defining a couple of buttons inside a third party’s ribbon gallery control. The gallery has a ItemsControl.ItemsSource which the XAML is populating with two Array items, these array items are a custom type which has a bitmap property and a ICommand property. Everything looks fine but I cannot get the array item property to bind to anything to do with the window’s data context. I have tried every trick i know, RelativeSource, ElementName but to no avail. Below is the XAML:

<ribbon:RibbonGallery.ItemsSource>
    <x:Array Type="{x:Type customUITypes:ClickableImage}">
        <customUITypes:ClickableImage   x:Name="BitmapAddWorkflow" Command="{Binding ElementName=MainView, Path=DataContext.MyCommandOne}">
            <customUITypes:ClickableImage.Bitmap>
                <BitmapImage UriSource="/Images/GalleryWorkflowAdd.png"/>
            </customUITypes:ClickableImage.Bitmap>
        </customUITypes:ClickableImage>
        <customUITypes:ClickableImage  x:Name="BitmapDeleteWorkflow" Command="{Binding ElementName=MainView, Path=DataContext.MyCommandTwo}">
            <customUITypes:ClickableImage.Bitmap>
                <BitmapImage UriSource="/Images/GalleryWorkflowDelete.png"/>
            </customUITypes:ClickableImage.Bitmap>
        </customUITypes:ClickableImage>                                        
    </x:Array>
</ribbon:RibbonGallery.ItemsSource>
<ribbon:RibbonGallery.ItemTemplate>
    <DataTemplate>
        <Button Command="{Binding Command}">
           <Image Margin="2" Source="{Binding Bitmap}" Stretch="None"/>
        </Button>
    </DataTemplate>
</ribbon:RibbonGallery.ItemTemplate>

Note : MainView is the name of the window, the data context is 100% what I want, I have no problems with any other bindings on this view, just within this array definition.

I guess I’m getting in a muddle with regards to the hierarchy of the objects i have access to but in my opinion regardless of whether I’m binding inside the array definition markup i should still be able to find an element and bind to it’s data context. Sometimes XAML seems to have inconsitency gotchas which creates hours of head scratching, just for something simple. I realise I could hard code some of this in my View Model, i.e. create my array items in the code and bind to that but I want to avoid doing that as it would mean having image paths hardcoded in code, i feel paths to images are a markup declaration.

Any help will be much appreciated.

Thanks

Paul

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T00:44:41+00:00Added an answer on May 27, 2026 at 12:44 am

    Have you used the “ditch ElementName and use Source & x:Reference“ trick yet?

    <Window.Resources>
        <x:Array x:Key="Items" Type="{x:Type customUITypes:ClickableImage}">
            <customUITypes:ClickableImage   x:Name="BitmapAddWorkflow"
                   Command="{Binding DataContext.MyCommandOne, Source={x:Reference MainWindow}}">
                <customUITypes:ClickableImage.Bitmap>
                    <BitmapImage UriSource="/Images/GalleryWorkflowAdd.png"/>
                </customUITypes:ClickableImage.Bitmap>
            </customUITypes:ClickableImage>
            <customUITypes:ClickableImage  x:Name="BitmapDeleteWorkflow"
                   Command="{Binding DataContext.MyCommandTwo, Source={x:Reference MainWindow}}">
                <customUITypes:ClickableImage.Bitmap>
                    <BitmapImage UriSource="/Images/GalleryWorkflowDelete.png"/>
                </customUITypes:ClickableImage.Bitmap>
            </customUITypes:ClickableImage>                                        
        </x:Array>
    </Window.Resources>
    <!-- ... -->
    <ribbon:RibbonGallery ItemsSource="{StaticResource Items}" ...
    

    Externalized array due to cyclical dependency (you can try to keep in place but i’m pretty sure the compiler won’t like it).


    Alternatively you can snatch the DataContext from a pipe object:

    <Window.Resources>
        <!-- Resource declaration gives you easy access using StaticResource -->
        <FrameworkElement Name="Pipe" Visibility="Hidden"/>
    </Window.Resources>
    <!-- Place it somewhere in the window where it can inherit the Window's DataContext -->
    <StaticResource ResourceName="Pipe"/>
    <!-- ... -->
    <customUITypes:ClickableImage   x:Name="BitmapAddWorkflow"
        Command="{Binding DataContext.MyCommandOne, Source={StaticResource Pipe}}">
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

On my MainPage.xaml I have some custom UserControls which I want to be able
I have some XAML <ItemsControl Name=mItemsControl> <ItemsControl.ItemTemplate> <DataTemplate> <TextBox Text={Binding Mode=OneWay} KeyUp=TextBox_KeyUp/> </DataTemplate> </ItemsControl.ItemTemplate>
Suppose I have some XAML like this: <Window.Resources> <v:MyClass x:Key=whatever Text=foo\nbar /> </Window.Resources> Obviously
I have some object that is instantiated in code behind, for instance, the XAML
I have authored some custom classes that I would like to create using XAML:
I have a simple WPF (XAML) file that has some animated shapes and text.
I have a very simple XAML form, that has one namespace definition. For some
I have some UI in VB 2005 that looks great in XP Style, but
I have some ASP.NET web services which all share a common helper class they
I have an Image declared in some XAML as: <Image Width=188 Height=56 HorizontalAlignment=Left VerticalAlignment=Bottom

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.