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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:51:54+00:00 2026-05-13T10:51:54+00:00

I have a wpf app with the datacontext set to an instance of a

  • 0

I have a wpf app with the datacontext set to an instance of a viewmodel class. It all works fine except where I need to access a property of the viewmodel in a listbox with the datacontext set to a collection that is contained in the ViewModel class. On msdn it says you can escape using the \ character but that has not worked for me

My code

public class StatusBoardViewModel : INotifyPropertyChanged
   {
    OIConsoleDataContext db = new OIConsoleDataContext();

    // the collection
    private IQueryable<Issue> issues;
    public IQueryable<Issue> Issues
    {
        get 
        {
            // Lazy load issues if they have not been instantiated yet
            if (issues == null)
                QueryIssues(); // This just runs a linq query to set the property
            return issues; 
        }
        set
        {
            if (issues != value)
            {
                issues = value;
                OnPropertyChanged("Issues");
            }
        }
    }
    // The property I need to access
    private bool showDetailListItems = true;
    public bool ShowDetailListItems
    {
        get
        {
            return showDetailListItems;
        }
        set
        {
            if (showDetailListItems != value)
            {
                showDetailListItems = value;
                OnPropertyChanged("ShowDetailListItems");
            }
        }
    }
}

in the window1.xaml.cs

//instantiate the view model 
StatusBoardViewModel statusBoardViewModel = new StatusBoardViewModel();

    public Window1()
    {
        InitializeComponent();
        // setting the datacontext
        this.DataContext = statusBoardViewModel;
    }

And the Xaml

    // This is in the Window1.xaml file
    <ListBox x:Name="IssueListBox"
              ItemsSource="{Binding Issues}" // Binds the listbox to the collection in the ViewModel
              ItemTemplate="{StaticResource ShowIssueDetail}" 
              IsSynchronizedWithCurrentItem="True"
              HorizontalContentAlignment="Stretch" BorderThickness="3"
              DockPanel.Dock="Top" VerticalContentAlignment="Stretch" 
              Margin="2" MinHeight="50" />

// The datatemplate from the app.xaml file
    <DataTemplate x:Key="ShowIssueDetail">
        <Border CornerRadius="3" Margin="2" MinWidth="400" BorderThickness="2" 
                BorderBrush="{Binding Path=IssUrgency, Converter={StaticResource IntToRYGBBoarderBrushConverter}}">
            <StackPanel Orientation="Vertical">
                <TextBlock Text="{Binding Path=IssSubject}" Margin="3" FontWeight="Bold" FontSize="14"/>

                <!--DataTrigger will collapse following panel for simple view-->
                 <StackPanel Name="IssueDetailPanel" Visibility="Visible" Margin="3">                     
                    <StackPanel Width="Auto" Orientation="Horizontal">
                        <TextBlock Text="Due: " FontWeight="Bold"/>
                        <TextBlock Text="{Binding Path=IssDueDate}" FontStyle="Italic" HorizontalAlignment="Left"/>
                    </StackPanel>
                    <StackPanel Width="Auto" Orientation="Horizontal">
                        <TextBlock Text="Category: " FontWeight="Bold"/>
                        <TextBlock Text="{Binding Path=IssCategory}"/>
                    </StackPanel>
                </StackPanel>

            </StackPanel>
        </Border>

        // This is where I have the issue, ShowDetailListItems is in the base class, not the collection
        <DataTemplate.Triggers>
            <DataTrigger Binding="{Binding Path=ShowDetailListItems, Mode=TwoWay}" Value="False">
                <Setter TargetName="IssueDetailPanel" Property="Visibility" Value="Collapsed"/>
            </DataTrigger>
        </DataTemplate.Triggers>
    </DataTemplate>

I have learned a TON doing this but this current issue is driving me batty, no luck with google, MSDN, SO or a couple books

I thought I would add this note: I am learning this in order to build some apps for my business, I am a rank beginner in wpf and xaml so I relize this is probably somthing silly. I would really like to find a good tutorial on datacontexts as what I do find is a dozen different “How To’s” that are all totally different. I know I have some big holes in my knowledge because I keep ending up with multiple instantiations of my viewmodel class when I try to create references to my datacontext in the codebehind, Window1.xaml and app.xaml files.

  • 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-13T10:51:55+00:00Added an answer on May 13, 2026 at 10:51 am

    Have you tried one of these?

    {Binding Path=ShowDetailListItems, ElementName=YourWindowName}
    

    or

    {Binding ShowDetailListItems, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.