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 324563
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T09:08:08+00:00 2026-05-12T09:08:08+00:00

I have 2 Xaml files, one containing a DataTemplate which has a resource definition

  • 0

I have 2 Xaml files, one containing a DataTemplate which has a resource definition for an Image brush, and the other containing a content control which presents this DataTemplate. The data template is bound to a view model class. Everything seems to work EXCEPT the ImageBrush resource, which just shows up white… Any ideas?

File 1: DataTemplate for ViewModel

<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:vm="clr-namespace:SEL.MfgTestDev.ESS.ViewModel" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    mc:Ignorable="d">

    <DataTemplate DataType="{x:Type vm:PresenterViewModel}">
        <DataTemplate.Resources>
            <ImageBrush x:Key="PresenterTitleBarFillBrush" 
            TileMode="Tile" 
            Viewbox="{Binding Path=FillBrushDimensions, Mode=Default}" 
            ViewboxUnits="Absolute" 
            Viewport="{Binding Path=FillBrushPatternSize, Mode=Default}" 
            ViewportUnits="Absolute" 
            ImageSource="{Binding Path=FillImage, Mode=Default}"/>
        </DataTemplate.Resources>
        <Grid d:DesignWidth="1440" d:DesignHeight="900">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="192"/>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="120"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>
            <DockPanel HorizontalAlignment="Stretch" Width="Auto" LastChildFill="True" Background="{x:Null}" Grid.ColumnSpan="2">
                <Image Source="{Binding Path=ImageSource, Mode=Default}"/>
                <Rectangle Fill="{DynamicResource PresenterTitleBarFillBrush}"/>
            </DockPanel>
        </Grid>
    </DataTemplate>

</ResourceDictionary>

File 2: Main Window Class which instanciates the DataTemplate Via it’s view model.

<Window x:Class="SEL.MfgTestDev.ESS.ESSMainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:vm="clr-namespace:SEL.MfgTestDev.ESS.ViewModel"
    Title="ESS Control Window" 
    Height="900" 
    Width="1440"
    WindowState="Maximized"
    WindowStyle="None"
    ResizeMode="NoResize"
    DataContext="{Binding}">

    <Window.Resources>
        <ResourceDictionary Source="PresenterViewModel.xaml" />
    </Window.Resources>

    <ContentControl>
        <ContentControl.Content>
            <vm:PresenterViewModel ImageSource="XAMLResources\SEL25YearsTitleBar.bmp" FillImage="XAMLResources\SEL25YearsFillPattern.bmp" FillBrushDimensions="0,0,5,110" FillBrushPatternSize="0,0,5,120"/>
        </ContentControl.Content>
    </ContentControl>

</Window>

And for the sake of completeness!
The CodeBehind for the View Model

using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace SEL.MfgTestDev.ESS.ViewModel
{
    public class PresenterViewModel : ViewModelBase
    {
        public PresenterViewModel()
        {

        }

        //DataBindings
        private ImageSource _imageSource;

        public ImageSource ImageSource
        {
            get 
            {
                return _imageSource; 
            }
            set 
            {
                if (_imageSource != value)
                {

                    _imageSource = value;
                    OnPropertyChanged("ImageSource");
                }
            }
        }

        private Rect _fillBrushPatternSize;

        public Rect FillBrushPatternSize
        {
            get
            {
                return _fillBrushPatternSize;
            }
            set
            {
                if (_fillBrushPatternSize != value)
                {
                    _fillBrushPatternSize = value;
                    OnPropertyChanged("FillBrushPatternSize");
                }
            }
        }

        private Rect _fillBrushDimensions;

        public Rect FillBrushDimensions
        {
            get
            {
                return _fillBrushDimensions;
            }
            set
            {
                if (_fillBrushDimensions != value)
                {
                    _fillBrushDimensions = value;
                    OnPropertyChanged("FillBrushDimensions");
                }
            }
        }

        private ImageSource _fillImage;

        public ImageSource FillImage
        {
            get
            {
                return _fillImage;
            }
            set
            {
                if (_fillImage != value)
                {
                    _fillImage = value;
                    OnPropertyChanged("FillImage");
                }
            }
        }


    }
}
  • 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-12T09:08:08+00:00Added an answer on May 12, 2026 at 9:08 am

    This is some kind of namescoping issue. If you move your resource to the level of the Grid rather than the DataTemplate itself, it will work:

    <DataTemplate DataType="{x:Type vm:PresenterViewModel}">
        <Grid>
            <Grid.Resources>
                <ImageBrush x:Key="PresenterTitleBarFillBrush"
                    TileMode="Tile"
                    Viewbox="{Binding Path=FillBrushDimensions, Mode=Default}"
                    ViewboxUnits="Absolute"
                    Viewport="{Binding Path=FillBrushPatternSize, Mode=Default}"
                    ViewportUnits="Absolute"
                    ImageSource="{Binding Path=FillImage, Mode=Default}"/>
            </Grid.Resources>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="192"/>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="120"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>
            <DockPanel HorizontalAlignment="Stretch" Width="Auto" LastChildFill="True" Background="{x:Null}" Grid.ColumnSpan="2">
                <Image Source="{Binding Path=ImageSource, Mode=Default}"/>
                <Rectangle Fill="{DynamicResource PresenterTitleBarFillBrush}"/>
            </DockPanel>
        </Grid>
    </DataTemplate>
    

    I think what’s happening is that the resources of the DataTemplate are in a separate namescope to the contents of the DataTemplate.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have resource dictionary files (MenuTemplate.xaml, ButtonTemplate.xaml, etc) that I want to use in
I have the following XAML code, which displays a picture (image inside borders) and
I have a simple WPF (XAML) file that has some animated shapes and text.
If I have a Xaml Window, how does one open it as a child
I have three xaml files + their code behind files in my Silverlight (C#)
I have a domain service, derived from LinqToEntitiesDomainService<FOOEntities> It has one method, IQueryable<Bar> GetBar().
I have some vector graphic files in XAML format and I would like to
I have 10 XAML files, each contaning a frame of an animation (they were
Really quick one, I have a small silverlight LOB application and in my App.xaml.cs
I have created a style for button control in App.xaml(RoundButton). I want to create

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.