binding

WPF binding OneWayToSource sets source property to “” when the DataContext is changed

随声附和 提交于 2019-12-12 10:59:30
问题 I have a OneWayToSource binding that is not behaving as I expected when I set the DataContext of the target control. The property of the source is being set to default instead of the value of the target control's property. I've created a very simple program in a standard WPF window that illustrates my problem: XAML <StackPanel> <TextBox x:Name="tb" Text="{Binding Path=Text,Mode=OneWayToSource,UpdateSourceTrigger=PropertyChanged}" TextChanged="TextBox_TextChanged"/> <Button Content="Set

Textbox Binding to both LostFocus and Property Update

血红的双手。 提交于 2019-12-12 10:48:50
问题 Currently I bind to my TextBox es as: Text="{Binding DocValue, Mode=TwoWay, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged}" This works great in getting every keystroke to do button status checking (which I want). In addition, I would like to track the LostFocus event on the TextBox (through binding) and do some additional calculations that might be too intensive for each keystroke. Anyone have thoughts on how to accomplish both? 回答1: Bind a command to the TextBox LostFocus

wpf: how to make ComboBoxItems hold integers in xaml

可紊 提交于 2019-12-12 10:29:28
问题 ok, I must be having a brain freeze here... I have a ComboBox with 6 items and I'm trying to bind the selected item to an integer value. Its not working, I suspect its because the ComboBoxItem's are strings. I don't feel like making a list in code behind just to fill this little box, so is there a way in xaml to tell the comboboxitems that they are holding integer numbers? Something like <x:Int>2</x:Int> maybe? xaml: <ComboBox SelectedItem="{Binding SavedPrintTicket.PagesPerSheet}">

Set AutoGenerateColumns=true and auto convert by the DataType

爷,独闯天下 提交于 2019-12-12 10:10:09
问题 I have a big ObservableCollection with 40+ columns that havn't the same type. Some of the columns are lists. I don't want to set AutoGenerateColumns=false because of the amont of the columns but the datagrid presents this in string of the datatype: System.Collection.Generic.List'1[System.double] and I want to present a string of the value like "10,2,30,5.2" Can I create a converter that check the typeof the value and return a string like this if it's a list? how can I read it from the Xaml (I

WPF ComboBox Binding not updating properly

吃可爱长大的小学妹 提交于 2019-12-12 09:41:06
问题 I have an updating issue with Binding in my ComboBox. I have created a simplified example illustrate this problem. I will paste all the related code below. So in the image above, I have a TextBlock (in black) that shows the 'SelectedPerson.FullName' property for the SelectedPerson. The FirstName and LastName properties of the SelectedPerson are shown in the 2 TextBoxes below the FullName. The ComboBox DisplayMemberPath is bound to 'FullName' and the combobox contains a list of Person objects.

Binding TreeView selection to ViewModel

瘦欲@ 提交于 2019-12-12 09:38:02
问题 So I have a TreeView that looks something like this: <TreeView Name="elementTreeView" ItemsSource="{Binding Elements}" Width="Auto" SelectedValuePath="Path" /> I also have a TextBlock defined as follows: <TextBlock Text="{Binding ElementName=elementTreeView, Path=SelectedValue}" /> My ModelView is pretty basic and contains exactly what you would expect. What I'm looking for is a way to bind a property in my ViewModel to SelectedValue. Right now, the text block displays what I need. Is there

WPF MVVM two-way updates

社会主义新天地 提交于 2019-12-12 09:27:27
问题 I'm trying to setup a working two-way update by using this example. These are the relevant code snippets: XAML: <Button Click="clkInit">Initialize</Button> <Button Click="clkStudent">Add student</Button> <Button Click="clkChangeStudent">Change students</Button> (...) <TabControl Name="tabControl1" ItemsSource="{Binding StudentViewModels}" > <TabControl.ItemTemplate> <DataTemplate> <TextBlock Text="{Binding Path=StudentFirstName}" /> </DataTemplate> </TabControl.ItemTemplate> <TabControl

DataGridView rows show up but no data

微笑、不失礼 提交于 2019-12-12 09:15:10
问题 I am trying to bind a collection (that inherits from BindingList) to a DataGridView. The grid headers show up fine and the I get the number of rows that I expect. However, the cells are empty. Has anyone else had this problem? If so, how did you resolve it? I've talked to someone else who had the same problem but they can't remember how they resolved it. I've tried to create a simple version that shows the problem but haven't had any luck. So I'm sorry, I haven't included any code. EDIT #1: I

Binding SelectedItem of ComboBox in DataGrid with different type

我的未来我决定 提交于 2019-12-12 09:01:39
问题 I have a DataGrid which contains ComboBox as column. Let consider DataGrid having ItemsSource as ObservableCollection and ComboBox ItemsSource is List . I want to set the ComboBox SelectedItem property based on property in DataGrid ItemsSource. However Product class has property ProductTypeId of type int and not ProductType. So how can I set ComboBox SelectedItem so that it display value of Product.ProductTypeId as selected. And also I want to bind SeletedItems with Mode = TwoWay so that

Binding a CollectionViewSource to ObservableCollection

房东的猫 提交于 2019-12-12 08:46:03
问题 Cannot bind the CollectionViewSource DocProps is a public property public ObservableCollection<DocProp> DocProps1 DataContext is self DataContext="{Binding RelativeSource={RelativeSource self}}" This works <ListBox Grid.Row="0" Grid.Column="0" ItemsSource="{Binding Path=DocProps1}"> I cannot wire up a CollectionViewSource to sort This does not even get DocProps1 <ListBox Grid.Row="0" Grid.Column="0"> <ListBox.ItemsSource> <Binding> <Binding.Source> <CollectionViewSource Source="{Binding Path