Click here to Skip to main content
15,886,919 members
Home / Discussions / WPF
   

WPF

 
QuestionSession variables in Silverlight or wcf service Pin
Nekkantidivya7-Dec-09 18:43
Nekkantidivya7-Dec-09 18:43 
AnswerRe: Session variables in Silverlight or wcf service Pin
Abhinav S10-Dec-09 6:37
Abhinav S10-Dec-09 6:37 
QuestionApplication menu button issue Pin
trey white7-Dec-09 8:40
trey white7-Dec-09 8:40 
QuestionWPF Ribbon bar issue Pin
trey white7-Dec-09 8:35
trey white7-Dec-09 8:35 
AnswerRe: WPF Ribbon bar issue Pin
trey white7-Dec-09 11:09
trey white7-Dec-09 11:09 
QuestionError in RoutedEventHandler() Pin
Anu_Bala7-Dec-09 0:04
Anu_Bala7-Dec-09 0:04 
QuestionUsing WPF Browser application in website. Pin
Hema Bairavan6-Dec-09 18:02
Hema Bairavan6-Dec-09 18:02 
QuestionSimple templated grid row. Pin
Dunge6-Dec-09 9:21
Dunge6-Dec-09 9:21 
Hi!
I'm kinda new to WPF and there's a lot of way to do stuff, I'm getting a bit mixed up. I would appreciate if someone could check the way I'm trying to do things and tell me what I understood wrong.

I'm trying to have a simple Windows with a grid. The rows in the grid are dynamically filled. I want to have a template for each row so they contain the same controls. I also want to have a feedback on these controls (when the selection of the first combobox change, populate the second combobox differently). And finally, I want to be able to see the selected values for each row controls when the user press the OK button.

Here is my XAML code:
<Window x:Class="WpfApplication.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:WpfApplication"
    Title="MainWindow" Height="300" Width="300">
    <Window.Resources>
        <DataTemplate x:Key="RowTemplate"
                      DataType="{x:Type local:RowViewModel}">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <StackPanel Orientation="Horizontal">
                    <TextBlock Text="Variable "/>
                    <TextBlock Text="{Binding Path=Slot}"/>
                </StackPanel>
                <ComboBox Grid.Column="1"
                          ItemsSource="{Binding Path=FirstList}"
                          SelectionChanged="Combo1SelectionChanged"/>
                <ComboBox Grid.Column="2"
                          ItemsSource="{Binding Path=SecondList}"
                          SelectionChanged="Combo2SelectionChanged"/>
            </Grid>
        </DataTemplate>
    </Window.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <Grid x:Name="MainGrid">
        </Grid>
        <StackPanel Orientation="Horizontal"
                    HorizontalAlignment="Right">
            <Button Content="Ok"/>
            <Button Content="Cancel"/>
        </StackPanel>
    </Grid>
</Window>


And my C# code:
using System;
using System.Collections.Generic;
using System.Linq;
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.Navigation;
using System.Windows.Shapes;
using System.ComponentModel;
using System.Collections.ObjectModel;

namespace WpfApplication
{
    public class List1 : ObservableCollection<string>
    {
        public List1() : base()
        {
            Add("A");
            Add("B");
            Add("C");
        }
    }

    public class List2 : ObservableCollection<string>
    {
        public List2(string basedOn) : base()
        {
            Add(basedOn + "1");
            Add(basedOn + "2");
            Add(basedOn + "3");
        }
    }

    public class RowViewModel : INotifyPropertyChanged
    {
        private int m_slot = 0;
        private List1 m_firstList = null;
        private List2 m_secondList = null;

        public RowViewModel(int Slot)
        {
            this.Slot = Slot;
            this.FirstList = new List1();
            this.SecondList = new List2(Slot.ToString());
        }

        public int Slot
        {
            get
            {
                return m_slot;
            }
            set
            {
                if(value != m_slot)
                {
                    m_slot = value;
                    NotifyPropertyChanged("Slot");
                }
            }
        }

        public List1 FirstList
        {
            get
            {
                return m_firstList;
            }
            set
            {
                if (value != m_firstList)
                {
                    m_firstList = value;
                    NotifyPropertyChanged("FirstList");
                }
            }
        }

        public List2 SecondList
        {
            get
            {
                return m_secondList;
            }
            set
            {
                if (value != m_secondList)
                {
                    m_secondList = value;
                    NotifyPropertyChanged("SecondList");
                }
            }
        }

        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;

        private void NotifyPropertyChanged(String info)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(info));
            }
        }

        #endregion
    }

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

            for(int i=0; i<10; i++)
            {
                RowDefinition rowDef = new RowDefinition();
                this.MainGrid.RowDefinitions.Add(rowDef);

                ItemsControl item = new ItemsControl();
//                item.ItemTemplate = this.RowTemplate;
                item.DataContext = new RowViewModel(i);
                item.SetValue(Grid.RowProperty, i);
                this.MainGrid.Children.Add(item);
            }
        }

        private void Combo1SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
        }

        private void Combo2SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
        }
    }
}


My problem currently is that I don't know which type of control to add to the grid because it's probably not a ItemsControl, nor a ContentControl? Also, the "RowTemplate" can't seem to be visible in my C# code, so I can't tell it to use it to display. Another problem is that I don't have access to the viewmodel and combobox directly in my SelectionChanged event, so I can't re-populate my list from there. I should probably do this in a totally different way, but as I said I'm getting mixed up.
QuestionScaleTransform sometimes produces glaring artifacts [modified] Pin
fjparisIII5-Dec-09 13:47
fjparisIII5-Dec-09 13:47 
AnswerRe: ScaleTransform sometimes produces glaring artifacts [modified] Pin
Insincere Dave6-Dec-09 13:55
Insincere Dave6-Dec-09 13:55 
GeneralRe: ScaleTransform sometimes produces glaring artifacts Pin
fjparisIII6-Dec-09 14:35
fjparisIII6-Dec-09 14:35 
GeneralRe: ScaleTransform sometimes produces glaring artifacts Pin
fjparisIII7-Dec-09 6:32
fjparisIII7-Dec-09 6:32 
GeneralRe: ScaleTransform sometimes produces glaring artifacts Pin
Insincere Dave7-Dec-09 13:43
Insincere Dave7-Dec-09 13:43 
GeneralRe: ScaleTransform sometimes produces glaring artifacts Pin
fjparisIII7-Dec-09 14:46
fjparisIII7-Dec-09 14:46 
GeneralRe: ScaleTransform sometimes produces glaring artifacts Pin
Insincere Dave7-Dec-09 16:30
Insincere Dave7-Dec-09 16:30 
GeneralRe: ScaleTransform sometimes produces glaring artifacts Pin
fjparisIII8-Dec-09 7:15
fjparisIII8-Dec-09 7:15 
GeneralRe: ScaleTransform sometimes produces glaring artifacts Pin
fjparisIII9-Dec-09 4:54
fjparisIII9-Dec-09 4:54 
GeneralRe: ScaleTransform sometimes produces glaring artifacts Pin
Insincere Dave9-Dec-09 6:19
Insincere Dave9-Dec-09 6:19 
GeneralRe: ScaleTransform sometimes produces glaring artifacts Pin
fjparisIII9-Dec-09 7:20
fjparisIII9-Dec-09 7:20 
GeneralRe: ScaleTransform sometimes produces glaring artifacts Pin
fjparisIII9-Dec-09 9:20
fjparisIII9-Dec-09 9:20 
GeneralRe: ScaleTransform sometimes produces glaring artifacts Pin
Insincere Dave9-Dec-09 9:48
Insincere Dave9-Dec-09 9:48 
GeneralRe: ScaleTransform sometimes produces glaring artifacts Pin
fjparisIII9-Dec-09 10:01
fjparisIII9-Dec-09 10:01 
GeneralRe: ScaleTransform sometimes produces glaring artifacts SOLVED!!! Pin
fjparisIII9-Dec-09 11:05
fjparisIII9-Dec-09 11:05 
GeneralRe: ScaleTransform sometimes produces glaring artifacts SOLVED!!! Pin
Insincere Dave9-Dec-09 14:58
Insincere Dave9-Dec-09 14:58 
GeneralRe: ScaleTransform sometimes produces glaring artifacts SOLVED!!! Pin
fjparisIII9-Dec-09 15:16
fjparisIII9-Dec-09 15:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.