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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T00:01:14+00:00 2026-06-11T00:01:14+00:00

All – Trying to do 2 things: I have a simple app and am

  • 0

All – Trying to do 2 things: I have a simple app and am trying to bind my Viewmodel collection to my view. Have 2 approaches in mind but am getting stuck on both of them:

Approach 1: Using Grid as a container to bind the textblock property.

Approach 2: Binding an attribute of the object directly to a textblock on my view (not using grid as a container and its Datacontext property)

Rule_Model_1.cs

public class Rule_Model_1
{
    public string topMessage { get; set; }
    public List<string> recipients { get; set; }
    public string bottomMessage { get; set; }
    public string hypLink { get; set; }
    public OCCBlock blockType { get; set; }

    public enum OCCBlock
    {
        HardBlock,
        SoftBlock,
        ModifyAndSend
    }
}

Rule_VM_1.cs

class Rule_VM_1
{
    #region Properties
    public List<Rule_Model_1> rule { get; set; }
    #endregion

    #region Constructor
    public Rule_VM_1()
    {
        #region Initializing a Rule
        rule = new List<Rule_Model_1>();

        rule.Add(new Rule_Model_1()
        {
            topMessage = "Lorem ipsum dolor sit amet.",
            recipients = new List<string> {"pr@hotmail.com", "pra@gmail.com"},
            bottomMessage = "Lorem ipsum dolor sit amet",
            hypLink = "http://www.abc.com",
            blockType = Rule_Model_1.OCCBlock.HardBlock
        });
        #endregion
    }
    #endregion
}

Rule_UI.xaml.cs

public partial class Rule_UI_1 : UserControl
{
    Rule_VM_1 rulevm1;
    public Rule_UI_1()
    {
        InitializeComponent();
        rulevm1 = new Rule_VM_1();
        DataContext = rulevm1; 
    }
}

Rule_UI.xaml

  <UserControl x:Class="OCC_WPF_POC.Rule_UI_1"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
         mc:Ignorable="d">
<GroupBox Header="Rule Details">
    <Grid HorizontalAlignment="Center" VerticalAlignment="Center">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto"></ColumnDefinition>
            <ColumnDefinition Width="*"></ColumnDefinition>
        </Grid.ColumnDefinitions>


        <Grid Grid.Column="1" DataContext="{Binding rule}">
            <Grid.RowDefinitions>
                <RowDefinition Height="50"></RowDefinition>
                <RowDefinition Height="200"></RowDefinition>
                <RowDefinition Height="50"></RowDefinition>
            </Grid.RowDefinitions>
            <TextBlock Grid.Row="0" Text="{Binding topmessage}" />
        </Grid>
    </Grid>
</GroupBox>

The view still shows nothing. Also as mentioned above – how do i have both the approaches working? Any code samples is greatly appreciated

Image AttachedWindow Image

  • 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-06-11T00:01:15+00:00Added an answer on June 11, 2026 at 12:01 am

    The problem is that you need a list view to bind to a collection property (rule). This should work:

    <ListBox Grid.Column="1" ItemsSource="{Binding rule}">
        <ListBox.ItemTemplate>
            <DataTemplate>
                <TextBlock Text="{Binding topmessage}" />
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>
    

    To bind to the grid, you can set the DataContext using an indexer []:

    <Grid Grid.Column="1" DataContext="{Binding rule[0]}">
        <TextBlock Grid.Row="0" Text="{Binding topmessage}" />
    </Grid>
    

    And without the Grid:

    <TextBlock Text="{Binding rule[0].topmessage}" />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

All this might look too trivial but read it through - I have simple
all. We're trying to get some intersect collisions working, but the problem experience is
all.I'm a beginner of Mysql and I have one simple question here. I want
All, I have a guestbook feature on my site and I keep getting spammed.
All I want is to make a simple user password login. I have put
All I'm trying to do is something fairly simple : Create a class (let's
All- I have an app in which the user enters the names of players
all, I am trying to multiply a matrix to a vector in OpenGL, but
All is in the question i have tried this : $('#my-div').css('box-shadow'); but it returns
All -- I have these two methods in one of my classes: public static

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.