binding

Binding to list causes memory leak

怎甘沉沦 提交于 2019-12-29 06:27:49
问题 When I bind an ItemsSource of a ListBox to a List the binding engine holds on to the list elements after the control is gone. This causes all the list elements to stay in memory. The problem goes away when using an ObservalbleCollection. Why does this happen? The xaml inside the window tag <Grid> <StackPanel> <ContentControl Name="ContentControl"> <ListBox ItemsSource="{Binding List, Mode=TwoWay}" DisplayMemberPath="Name"/> </ContentControl> <Button Click="Button_Click">GC</Button> <

How to set the DataSource of a DataGrid in WPF?

霸气de小男生 提交于 2019-12-29 06:13:48
问题 I need to set a table from a database to be the DataSource of a GridGrid in WPF. In Windows Forms the property is called DataSource but in WPF no such property exists, so how can i do it? 回答1: You can use the ItemsSource property : <ListView ItemsSource="{Binding YourData}"> <ListView.View> <GridView> <!-- The columns here --> </GridView> </ListView.View> </ListView> If you prefer to use code-behind rather than a binding, just give a name to the ListView and set the ItemsSource property in

How to display value of List#size() in JSF EL?

爱⌒轻易说出口 提交于 2019-12-29 05:43:05
问题 I'd like to know if there's a way to bind the returned value of a method into a JSF component. I'll explain myself better. Let's say I have a class like this: public class Document { private List<Attachment> attachments; //getter and setter here } this class is exposed to jsf through a registered managed bean in a property called currentDocument, and used in a jsf this way <h:outputText value="#{myManagedBean.currentDocument.attachment.size}" /> This isn't correct, I know. But what is the

Dynamic Scoping - Deep Binding vs Shallow Binding

孤街浪徒 提交于 2019-12-29 04:29:09
问题 I've been trying to get my head around shallow binding and deep binding, wikipedia doesn't do a good job of explaining it properly. Say I have the following code, what would the output be if the language uses dynamic scoping with a) deep binding b) shallow binding? x: integer := 1 y: integer := 2 procedure add x := x + y procedure second(P:procedure) x:integer := 2 P() procedure first y:integer := 3 second(add) ----main starts here--- first() write_integer(x) 回答1: Deep binding binds the

INotifyPropertyChanged or INotifyCollectionChanged with DataTable?

柔情痞子 提交于 2019-12-29 01:14:49
问题 Hi i am having some troube with DataTables. So What i need is to detect whenever i change any cell in the DataGrid of the DataTable that is binded. How to do it? With INotifyPropertyChanged or with INotifyCollectionChanged ? Note: I am trying with INotifyPropertyChanged but it only detects when i set some value in the DataTable, and never when i change any value of any cell in the DataGrid, i already have tried OneWay and TwoWay but nothing happens. Thanks in advance! 回答1: The datagrid would

wpf dictionary binding where key=variable

我们两清 提交于 2019-12-29 00:41:09
问题 I have a test dictionary MyDict = new Dictionary<string, Uri> { {"First", new Uri("alma.jpg", UriKind.Relative)}, {"Second", new Uri("korte.jpg", UriKind.Relative)} }; and a simple XAML <TextBlock Text="{Binding MyDict[First]}" FontSize="13" Width="200" Height="30" /> That shows perfectly the First key element Value What I want is I have a string variable: DictKey Lets DictKey="First" How to rewrite the XAML to use this variable <TextBlock Text="{Binding MyDict[???DictKey????]}" FontSize="13"

Databind from XAML to code behind

女生的网名这么多〃 提交于 2019-12-28 20:38:33
问题 I have this Text dependency property in code behind: public static DependencyProperty TextProperty = DependencyProperty.Register("Text", typeof(string), typeof(MainWindow), new PropertyMetadata("Hello world")); public string Text { get { return (string)GetValue(TextProperty); } set { SetValue(TextProperty, value); } } I want to bind content of label to that Text property so that the label displays actual value of Text property and vice-versa. <Label Content="{Binding ???}" /> How can I do it

Binding to DateTime.Now. Update the value

此生再无相见时 提交于 2019-12-28 20:32:16
问题 Well, I needed to bind DateTime.Now to a TextBlock, I used that: Text="{Binding Source={x:Static System:DateTime.Now},StringFormat='HH:mm:ss tt'}" Now, how to force it to update? It get's the time when control is loaded and wouldn't update it... 回答1: Edited (I didn't account for him wanting to auto-update): Here's a link of a 'Ticker' class that uses INotifyPropertyChanged so it'll auto-update. Here's the code from the site: namespace TheJoyOfCode.WpfExample { public class Ticker :

WPF ViewModel Commands CanExecute issue

岁酱吖の 提交于 2019-12-28 13:48:49
问题 I'm having some difficulty with Context Menu commands on my View Model. I'm implementing the ICommand interface for each command within the View Model, then creating a ContextMenu within the resources of the View (MainWindow), and using a CommandReference from the MVVMToolkit to access the current DataContext (ViewModel) Commands. When I debug the application, it appears that the CanExecute method on the command is not being called except at the creation of the window, therefore my Context

How to Bind specific Columns of a datatable to a DataGridView?

为君一笑 提交于 2019-12-28 13:36:31
问题 My DataTable has three columns fetched from a database, while I need to bind only two columns of it to a DataGridView . Can you please help me with it? 回答1: Create the columns for the DataGridView yourself. Try something like this. DataGridView dataGridView1 = new DataGridView(); BindingSource bindingSource1 = new BindingSource(); dataGridView1.ColumnCount = 2; dataGridView1.Columns[0].Name = "Field1"; dataGridView1.Columns[0].DataPropertyName = "Field1"; dataGridView1.Columns[1].Name =