有谁知道为什么这段代码不起作用:
public class CollectionViewModel : ViewModelBase {
public ObservableCollection<EntityViewModel> ContentList
{
get { return _contentList; }
set
{
_contentList = value;
RaisePropertyChanged("ContentList");
//I want to be notified here when something changes..?
//debugger doesn't stop here when IsRowChecked is toggled
}
}
}
public class EntityViewModel : ViewModelBase
{
private bool _isRowChecked;
public bool IsRowChecked
{
get { return _isRowChecked; }
set { _isRowChecked = value; RaisePropertyChanged("IsRowChecked"); }
}
}
Run Code Online (Sandbox Code Playgroud)
ViewModelBase包含所有东西RaisePropertyChanged等等,它除了这个问题以外的所有其他工作..
我有一个这样的课:
public class PersonViewModel : ViewModelBase //Here is the INotifyPropertyChanged Stuff
{
public PersonViewModel(Person person)
{
PersonEntity = person;
}
public Person PersonEntity {
get { return PersonEntity.Name; }
private set { PersonEntity.Name = value; RaisePropertyChanged("PersonEntity");
}
public string Name {
get { return PersonEntity.Name; }
set { PersonEntity.Name = value; RaisePropertyChanged("Name");
}
public int Age{
get { return PersonEntity.Age; }
set { PersonEntity.Age= value; RaisePropertyChanged("Age");
}
public void ChangePerson(Person newPerson)
{
//Some Validation..
PersonEntity = newPerson;
}
Run Code Online (Sandbox Code Playgroud)
我的TextBoxes绑定到ViewModel的Name和Age.如果我在ViewModel中更改_person对象,我是否必须再次为每个属性调用一个RaisePropertyChanged,或者是否有办法自动执行此操作(在我的concret示例中,我有大约15个属性..)?
谢谢你的帮助. …
我正在尝试在C#中为WPF DataBinding创建一个Observable Dictionary Class.我在这里找到了Andy的一个很好的例子:双向数据绑定在WPF中的字典
据此,我试图将代码更改为以下内容:
class ObservableDictionary : ViewModelBase
{
public ObservableDictionary(Dictionary<TKey, TValue> dictionary)
{
_data = dictionary;
}
private Dictionary<TKey, TValue> _data;
public Dictionary<TKey, TValue> Data
{
get { return this._data; }
}
private KeyValuePair<TKey, TValue>? _selectedKey = null;
public KeyValuePair<TKey, TValue>? SelectedKey
{
get { return _selectedKey; }
set
{
_selectedKey = value;
RaisePropertyChanged("SelectedKey");
RaisePropertyChanged("SelectedValue");
}
}
public TValue SelectedValue
{
get
{
return _data[SelectedKey.Value.Key];
}
set
{
_data[SelectedKey.Value.Key] = value;
RaisePropertyChanged("SelectedValue");
}
}
}
Run Code Online (Sandbox Code Playgroud)
}
不幸的是我仍然不知道如何传递"一般"字典对象..任何想法? …
有谁知道如何禁用文本包装RichTextBox?例如,如果我有一个不适合窗口的大字符串,RichTextBox则将字符串中无法显示新行的部分放置.我想禁用它(并且仅通过使用它使其可见Scrollbar).
非常感谢.
干杯
有谁知道是否有一个隐藏GridViewColumn的选项,如下所示:
<ListView.View>
<GridView>
<GridViewColumn Header="Test" IsVisible="{Binding Path=ColumnIsVisible}" />
</GridView>
<ListView.View>
Run Code Online (Sandbox Code Playgroud)
非常感谢!
编辑:为清楚起见
不幸的是,没有"IsVisible"属性.我正在寻找一种方法来创造它.
编辑:基于反馈的解决方案如下:
<GridViewColumn DisplayMemberBinding="{Binding Path=OptionColumn1Text}"
Width="{Binding Path=SelectedEntitiy.OptionColumn1Width}">
<GridViewColumnHeader Content="{Binding Path=SelectedEntitiy.OptionColumn1Header}" IsEnabled="{Binding Path=SelectedEntitiy.OptionColumn1Width, Converter={StaticResource widthToBool}}" />
</GridViewColumn>
public class WidthToBooleanConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return (int)value > 0;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
Run Code Online (Sandbox Code Playgroud)
谢谢大家!
干杯
我想做以下事情:
public List<Users> PreLoadedUserList { get; set; }
public List<RowEntries> SomeDataRowList { get; set; }
public class Users
{
public int Age { get; set; }
public string Name { get; set; }
}
public class SomeDataRowList
{
public int UserAge { get; set;
}
Run Code Online (Sandbox Code Playgroud)
现在我的(WPF Toolkit)DataGrid看起来像这样:
<my:DataGrid AutoGenerateColumns="False" MinHeight="200"
ItemsSource="{Binding Path=SomeDataRowList}">
<my:DataGridComboBoxColumn Header="Age"
ItemsSource="{Binding Path=PreLoadedUserList}"
DisplayMemberPath="Name"
SelectedValueBinding="{Binding Path=UserAge}"/>
</my:DataGrid>
Run Code Online (Sandbox Code Playgroud)
现在我的问题是,PreLoadedUserList在ItemSource(SomeDataRowList)之外,我不知道如何绑定到它之外的东西.我真正想要它: - 在ComboBox中显示PreLoadedUserList - 将(RowEntries)SelectedItem.UserAge的值设置为所选ComboboxItem.Age的值
如果我的解释太奇怪,请告诉我:-)
谢谢,干杯
我在其中一列上有一个带有datetime64对象的pandas数据帧.
time volume complete closeBid closeAsk openBid openAsk highBid highAsk lowBid lowAsk closeMid
0 2016-08-07 21:00:00+00:00 9 True 0.84734 0.84842 0.84706 0.84814 0.84734 0.84842 0.84706 0.84814 0.84788
1 2016-08-07 21:05:00+00:00 10 True 0.84735 0.84841 0.84752 0.84832 0.84752 0.84846 0.84712 0.8482 0.84788
2 2016-08-07 21:10:00+00:00 10 True 0.84742 0.84817 0.84739 0.84828 0.84757 0.84831 0.84735 0.84817 0.847795
3 2016-08-07 21:15:00+00:00 18 True 0.84732 0.84811 0.84737 0.84813 0.84737 0.84813 0.84721 0.8479 0.847715
4 2016-08-07 21:20:00+00:00 4 True 0.84755 0.84822 0.84739 0.84812 0.84755 0.84822 …Run Code Online (Sandbox Code Playgroud) 如何在DataTemplate中获取元素的绑定路径?我的XAML看起来像这样:
<GridViewColumn Header="Double">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding TotalValues, Mode=OneWay, StringFormat=\{0:0\'0.00\}, Converter={StaticResource GridValueConverter}}" TextAlignment="Right" Width="auto"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Comments" DisplayMemberBinding="{Binding Path=Comments, Mode=OneWay}" Width="auto"/>
Run Code Online (Sandbox Code Playgroud)
获取"普通"GridViewColumnHeader.DisplayMemberBinding的绑定路径是
var field = (string)((Binding)((GridViewColumnHeader)e.OriginalSource).Column.DisplayMemberBinding).Path.Path;
Run Code Online (Sandbox Code Playgroud)
如何才能获得相同的绑定路径TextBlock.Text?
我有一个
List<DetailObject> someList;
Run Code Online (Sandbox Code Playgroud)
看起来像这样:
public class DetailObject
{
public string Titel { get; set; }
public int Value1 { get; set; }
public int Value2 { get; set; }
public int Value3 { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
有谁知道我如何使用(使用DataGrid.AutoGenerateColumns ="True")'string Titel'的值作为RowHeader和其他成员作为"行"内容?没有任何修改,它会显示"Titel"作为ColumnHeader并将Titel的值显示为行,将"Value1"的dito显示为ColumnHeader,将Value1的值显示为Rows等.
谢谢你的帮助!
干杯
编辑:为了更好地理解,这就是我所拥有的
[Titel] [Value1] [Value2] [Value3]
[Item1.Titel] [Item1.Value1] [Item1.Value2] [Item1.Value3]
[Item2.Titel] [Item2.Value1] [Item2.Value2] [Item2.Value3]
[Item3.Titel] [Item3.Value1] [Item3.Value2] [Item3.Value3]
Run Code Online (Sandbox Code Playgroud)
这就是我要找的东西:
[Item1.Titel] [Item2.Titel] [Item3.Titel]
[Item1.Value1] [Item2.Value1] [Item3.Value1]
[Item1.Value2] [Item2.Value2] [Item3.Value2]
[Item1.Value3] [Item2.Value3] [Item3.Value3]
Run Code Online (Sandbox Code Playgroud)
EDIT2:我在这里找到了一个不错的方法:http: //codemaverick.blogspot.com/2008/02/transpose-datagrid-or-gridview-by.html
c# ×9
wpf ×8
binding ×2
datagrid ×2
columnheader ×1
combobox ×1
data-binding ×1
dataframe ×1
datatemplate ×1
listview ×1
numpy ×1
pandas ×1
popup ×1
python ×1
richtextbox ×1
visibility ×1
word-wrap ×1