Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Title="Window1" Height="300" Width="300">
- <Grid>
- <ListView Name="TestList">
- <ListView.View>
- <GridView>
- <GridViewColumn Header="Strings">
- <GridViewColumn.CellTemplate>
- <DataTemplate>
- <TextBox Text="{Binding Path=String, Mode=TwoWay}"/>
- </DataTemplate>
- </GridViewColumn.CellTemplate>
- </GridViewColumn>
- <GridViewColumn Header="Bools">
- <GridViewColumn.CellTemplate>
- <DataTemplate>
- <CheckBox IsChecked="{Binding Path=Bool, Mode=TwoWay}"/>
- </DataTemplate>
- </GridViewColumn.CellTemplate>
- </GridViewColumn>
- </GridView>
- </ListView.View>
- </ListView>
- </Grid>
- </Window>
- using System.Collections.Generic;
- using System.Windows;
- namespace GridViewTextbox
- {
- public partial class Window1 : Window
- {
- private List<TestRow> _rows = new List<TestRow>();
- public Window1()
- {
- InitializeComponent();
- _rows.Add(new TestRow("a", false));
- _rows.Add(new TestRow("b", true));
- _rows.Add(new TestRow("c", false));
- TestList.ItemsSource = _rows;
- TestList.DataContext = _rows;
- }
- }
- public class TestRow : System.Windows.DependencyObject
- {
- public TestRow(string s, bool b)
- {
- String = s;
- Bool = b;
- }
- public string String
- {
- get { return (string)GetValue(StringProperty); }
- set { SetValue(StringProperty, value); }
- }
- // Using a DependencyProperty as the backing store for String. This enables animation, styling, binding, etc...
- public static readonly DependencyProperty StringProperty =
- DependencyProperty.Register("String", typeof(string), typeof(TestRow), new UIPropertyMetadata(""));
- public bool Bool
- {
- get { return (bool)GetValue(BoolProperty); }
- set { SetValue(BoolProperty, value); }
- }
- // Using a DependencyProperty as the backing store for Bool. This enables animation, styling, binding, etc...
- public static readonly DependencyProperty BoolProperty =
- DependencyProperty.Register("Bool", typeof(bool), typeof(TestRow), new UIPropertyMetadata(false));
- }
- }
- public static readonly DependencyProperty BoolProperty =
- DependencyProperty.Register("Bool", typeof(bool), typeof(TestRow), new UIPropertyMetadata(false, OnBoolChanged));
- private static void OnBoolChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
- {
- //this method will be called everytime Bool changes value
- }
- yourControl.SetValue(TestRow.StringProperty, someValue);
- yourControl.String = someValue;
Add Comment
Please, Sign In to add comment