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

  • Home
  • SEARCH
  • 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 1012417
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T09:56:36+00:00 2026-05-16T09:56:36+00:00

my xml is : <Window.Resources> <Style TargetType=ListViewItem> <Setter Property=HorizontalContentAlignment Value=Stretch /> </Style> </Window.Resources> <Grid

  • 0

my xml is :

<Window.Resources>
    <Style TargetType="ListViewItem">
        <Setter Property="HorizontalContentAlignment" Value="Stretch" />
    </Style>
</Window.Resources>


<Grid  >
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="381*" />
        <ColumnDefinition Width="20*" />
        <ColumnDefinition Width="101*" />
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
        <RowDefinition Height="110*" />
        <RowDefinition Height="201*" />
    </Grid.RowDefinitions>
    <StackPanel Margin="320,0,0,0" Grid.RowSpan="2">
        <ListView ItemsSource="{Binding employeeCollection}">
            <ListView.View>
                <GridView>

                    <GridViewColumn Header="Employee ID" DisplayMemberBinding="{Binding Path=EmployeeID}"/>
                    <GridViewColumn Header="First Name" DisplayMemberBinding="{Binding Path=FirstName}"/>
                    <GridViewColumn Header="Last Name" DisplayMemberBinding="{Binding Path=LastName}"/>
                    <GridViewColumn Header="start" DisplayMemberBinding="{Binding Path=startHR}"/>
                    <GridViewColumn Header="finish" DisplayMemberBinding="{Binding Path=finishHR}">

                </GridViewColumn>
            </GridView>
    </ListView.View>

        </ListView>
    </StackPanel>
            <StackPanel Margin="2,0,0,137" Grid.RowSpan="2" Grid.ColumnSpan="2" Grid.Column="1">
        <ListBox FontFamily="Guttman Yad-Brush" BorderBrush="AliceBlue" BorderThickness="5" ItemsSource="{Binding Path=dateItems}" DisplayMemberPath="Name" SelectedValuePath="Name" SelectedValue="{Binding Path=dateItem}" Width="233" Height="164" />
    </StackPanel>
    <Button Click="Button_Click" Width="102" Height="34" Margin="0,98,-1,69" Grid.Row="1" Grid.Column="2" Content="בחר" FontFamily="Guttman Yad-Brush" Background="AliceBlue"></Button>
    <TextBox Name="dateTextBox" Grid.Column="1" Margin="26,152,0,33" Grid.Row="1" FontFamily="Guttman Yad-Brush" Grid.ColumnSpan="2" />
    <Calendar SelectedDate="{Binding Path=SelectedDate}" Height="168" Name="calendar1" Width="182" SelectedDatesChanged="calendar1_SelectedDatesChanged" Margin="66,68,485,115" Grid.RowSpan="2" />
</Grid>

–>

–>

this is the start window class :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.ComponentModel;
using System.Windows.Data;

using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;


namespace WpfApplication1
{

public partial class MainWindow : Window
{
    ConnectionViewModel vm;

    public MainWindow()
{
    InitializeComponent();
    vm = new ConnectionViewModel();

    DataContext = vm;
}
    private void Button_Click(object sender, RoutedEventArgs e)
    {
        //((ConnectionViewModel)DataContext).dateItems = "test";
        if (vm.cm.dateItem.ToString() != null)
        {
            dateTextBox.Text = vm.cm.dateItem.ToString();
            vm.em.insert();
        }
    }

    private void calendar1_SelectedDatesChanged(object sender, SelectionChangedEventArgs e)
    {

            string []s = calendar1.SelectedDate.ToString().Split(' ');
            dateTextBox.Text = s[0];
    }

 }

public class ConnectionViewModel
{

    public DateConectionModule cm;
    public employeesGrid em;

    public ConnectionViewModel()
    {

        cm = new DateConectionModule();
        em = new employeesGrid();

    }

    public CollectionView dateItems
    {
        get { return cm.dateItems; }
    }
    public string dateItem
    {
        get {return cm.dateItem;} 
        set{ cm.dateItem = value;}
    }
    public CollectionView employeeCollection
    {
        get { return em.employeeCollection; }
    }



}




public class DateConectionModule : INotifyPropertyChanged
{

    public static string[] datesString = { "01.01.2011", "02.01.2011", "03.01.2011", "04.01.2011", "05.01.2011" };

    public DateConectionModule()
    {

        employeesGrid em = new employeesGrid();
        IList<dateItem> list = new List<dateItem>();
        //query to database should be here
        foreach (string dataString in datesString)
        {
            list.Add(new dateItem(dataString));
        }
        _dateItemList = new CollectionView(list);
    }
    private readonly CollectionView _dateItemList;
    private string m_dateItem;

    public CollectionView dateItems
    {
        get { return _dateItemList; }
    }

    public string dateItem
    {
        get { return m_dateItem; }
        set
        {
            if (m_dateItem == value)
                return;
            m_dateItem = value;
            OnPropertyChanged("dateItem");
        }
    }
    private void OnPropertyChanged(string propertyName)
    {
        if (PropertyChanged != null)
            PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
    }
    public event PropertyChangedEventHandler PropertyChanged;
}





public class dateItem
{
    public string Name { get; set; }
    public dateItem(string name)
    {
        Name = name;
    }
}

public class employeesGrid : INotifyPropertyChanged
{
    private CollectionView _dateItemList;
    private string m_dateItem;


    public employeesGrid()
    {
        IList<employiesData> list = new List<employiesData>();
        //query to database should be here
        list.Add(new employiesData{
        EmployeeID =  "036854768",
        FirstName = "yoav" ,
        LastName = "stern",
        startHR = "1600" ,
        finishHR = "0200"});
        _dateItemList = new CollectionView(list);
    }

    public void insert()
    {
        IList<employiesData> list = new List<employiesData>();
        //query to database should be here
        list.Add(new employiesData
        {
            EmployeeID = "0234235345",
            FirstName = "shoki",
            LastName = "zikri",
            startHR = "1600",
            finishHR = "0200"
        });
        _dateItemList = new CollectionView(list);
        OnPropertyChanged("employeeCollection");
    }

    public CollectionView employeeCollection
    {
        get { return _dateItemList; }

        set
        {
            if (_dateItemList == value) 
                return;
            _dateItemList = value;
            OnPropertyChanged("employeeCollection");
        }
    }
    private void OnPropertyChanged(string propertyName)
    {
        if (PropertyChanged != null)
            PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
    }
    public event PropertyChangedEventHandler PropertyChanged;

}
public class employiesData
{
    public string EmployeeID { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public string startHR { get; set; }
    public string finishHR { get; set; }
}

}

1.i want thar when insertTest is called the UI will load my new values

2.this is my first wpf work so any advices on how to make things more readable,effican,simple and notes about the my poor architecture i know it’s crapy can some

  • 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-16T09:56:36+00:00Added an answer on May 16, 2026 at 9:56 am

    Below my points

    1- What is the use of ConnectionViewModel class , it is just warpping DataConnectionViewModel so i would suggest that you can get rid of ConnectionViewModel() and use DataConnectionViewModel.

    2-i think you can Get rid of employeesGrid class because all you need a collection of employees so rather than useing a seprate collection class, make an observrablecollection in DataConnectionViewModel() class.

    3- Use Wpf- Model -View-ViewModel Template this gives you better idea

    4- i have just refacror your code and create a similar application which uses MVVM and ObservableCollection and much simpler to use.

    my xaml

    <Window.Resources>
        <Style TargetType="ListViewItem">
            <Setter Property="HorizontalContentAlignment" Value="Stretch"></Setter>
        </Style>
    </Window.Resources>
    
    
    <Grid  >
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="381*" />
            <ColumnDefinition Width="20*" />
            <ColumnDefinition Width="101*" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="110*" />
            <RowDefinition Height="201*" />
        </Grid.RowDefinitions>
        <StackPanel Margin="320,0,0,0" Grid.RowSpan="2">
            <ListView ItemsSource="{Binding EmpList}">
                <ListView.View>
                    <GridView>
    
                        <GridViewColumn Header="Employee ID" DisplayMemberBinding="{Binding Path=EmployeeID}"/>
                        <GridViewColumn Header="First Name" DisplayMemberBinding="{Binding Path=FirstName}"/>
                        <GridViewColumn Header="Last Name" DisplayMemberBinding="{Binding Path=LastName}"/>
                        <GridViewColumn Header="start" DisplayMemberBinding="{Binding Path=startHR}"/>
                        <GridViewColumn Header="finish" DisplayMemberBinding="{Binding Path=finishHR}">
    
                        </GridViewColumn>
                    </GridView>
                </ListView.View>
    
            </ListView>
        </StackPanel>
        <StackPanel Margin="2,0,0,137" Grid.RowSpan="2" Grid.ColumnSpan="2" Grid.Column="1">
            <ListBox FontFamily="Guttman Yad-Brush" BorderBrush="AliceBlue" BorderThickness="5" ItemsSource="{Binding Path=dateItems}" DisplayMemberPath="Name" SelectedValuePath="Name" SelectedValue="{Binding Path=dateItem}" Width="233" Height="164" />
        </StackPanel>
        <!--<Button Click="Button_Click" Width="102" Height="34" Margin="0,98,-1,69" Grid.Row="1" Grid.Column="2" Content="בחר" FontFamily="Guttman Yad-Brush" Background="AliceBlue"></Button>-->
        <TextBox Name="dateTextBox" Grid.Column="1" Margin="26,152,0,33" Grid.Row="1" FontFamily="Guttman Yad-Brush" Grid.ColumnSpan="2" />
        <!--<Calendar SelectedDate="{Binding Path=SelectedDate}" Height="168" Name="calendar1" Width="182" SelectedDatesChanged="calendar1_SelectedDatesChanged" Margin="66,68,485,115" Grid.RowSpan="2" />-->
    </Grid>
    

    My Code

    1-

    Create DataConnectionViewModel which is inheriting ViewModelBase class.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Employee.Models;
    using System.Collections.ObjectModel;

    namespace Employee.ViewModels
    {
    public class DateConectionModule : ViewModelBase
    {
    #region ” Instance Variables ”
    public static string[] datesString = { “01.01.2011”, “02.01.2011”, “03.01.2011”, “04.01.2011”, “05.01.2011” };
    #endregion ” Instance Variables “

        #region " Constructor "
    
        public DateConectionModule()
        {
            CreateEmployeeData();
        }
        #endregion " Constructor "
    
    
        #region " Public Properties "
    
        public ObservableCollection<EmployeeData> EmpList { get; set; }
    
    
    
        #endregion " Public Properties "
    
    
        #region " Helper Methods "
    
        private void CreateEmployeeData()
        {
            EmpList = new ObservableCollection<EmployeeData>();
            EmpList.Add
                (
                 new EmployeeData() {  EmployeeID="1", LastName="Gates", FirstName="Bill", finishHR="", startHR =""  }
                );
    
        }
    
        #endregion " Helper Methods "
    
    
    
    
    } 
    

    }

    2- ViewModelBAse Class

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Linq;
    using System.Text;
    using System.Windows;
    using System.Windows.Input;

    namespace Employee.ViewModels
    {
    ///
    /// Provides common functionality for ViewModel classes
    ///
    public abstract class ViewModelBase : INotifyPropertyChanged
    {
    public event PropertyChangedEventHandler PropertyChanged;

        protected void OnPropertyChanged(string propertyName)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
    
            if (handler != null)
            {
                handler(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    
    }
    

    }

    3- Set the Data Context in the MainWindow.Xaml.cs

    public partial class MainView : Window
    {
    public MainView()
    {
    InitializeComponent();

            this.DataContext = new DateConectionModule();
        }
    }
    

    there are lot of other things like Dependency Injection, etc.. but for your case , you can write a controller which call your dataservice to give you employess list than assign list to the observablecollection.

    4- i can suggest read abot Prism framework which gives you very much flexibility during application management and also in TDD.

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

Sidebar

Related Questions

Using WiX (Windows Installer XML) I have created an MSI installer which installs Word
I need the simplest editor with utf-8 support for editing xml files in windows;
I've got a little c# windows service that periodically pulls xml from a web
The XML Schema Part 2 specifies that an instance of a datatype that is
This XML file contained archived news stories for all of last year. I was
The XML I'm trying to validate is as follows: <root> <element attribute=foo> <bar/> </element>
Which XML validation tools can you recommend for both performance and accuracy, each of
An XML attribute declared as xs:boolean can acceptable be true, false, 0 or 1.
I have a complete XML document in a string and would like a Document
I have an XML object (loaded using XMLHTTPRequest 's responseXML ). I have modified

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.