![]() The basic features work, although with some inefficiencies, but advanced features may encounter known bugs. Warning: 50 : Using CollectionView directly is not fully supported. Maybe there is an issue with the CollectionView? I noticed a warning in the output console: If I change the PhonebookEntries property on the ConnectionViewModel to be of type ReadOnl圜ollection, the TwoWay binding of the SelectedValue property on the combobox works fine. Public event Propert圜hangedEventHandler Propert圜hanged Įdit: Geoffs second example does not seem to work, which seems a bit odd to me. Propert圜hanged(this, new Propert圜hangedEventArgs(propertyName)) Private void OnPropert圜hanged(string propertyName) Private readonly CollectionView _phonebookEntries _phonebookEntries = new CollectionView(list) Public class ConnectionViewModel : INotifyPropert圜hanged ((ConnectionViewModel)DataContext).PhonebookEntry = "test" Private void Button_Click(object sender, RoutedEventArgs e) I can set the viewmodels PhoneBookEnty property and the selected item in the combobox changes, and I can change the selected item in the combobox and the view models PhoneBookEntry property is set correctly.Īnd here is my code-behind: namespace WpfApplication6ĬonnectionViewModel vm = new ConnectionViewModel() I copied you code and made some minor modifications, and it seems to work fine. Have you set the DataContext to your ConnectionViewModel object? You set the DisplayMemberPath and the SelectedValuePath to "Name", so I assume that you have a class PhoneBookEntry with a public property Name. Target.SetValue(DialogResultProperty, value) Public static void SetDialogResult(Window target, bool? value) Window.DialogResult = e.NewValue as bool? New PropertyMetadata(DialogResultChanged)) Public static readonly DependencyProperty DialogResultProperty = Here's the code for DialogCloser: using System.Windows Just put a bool? DialogResult property on your ViewModel and implement INotifyPropert圜hanged, and voilà, your ViewModel can close the Window (and set its DialogResult) just by setting a property. This is almost as clean as if the WPF team had gotten it right and made DialogResult a dependency property in the first place. No styles, no triggers instead, you can just do this: I was inspired by Thejuan's answer to write a simpler attached property. SetPassword(passwordBox, passwordBox.Password) Private static void PasswordChanged(object sender, RoutedEventArgs e) Private static void Attach(DependencyObject sender, PasswordBox.PasswordChanged += PasswordChanged PasswordBox.Password = (string)e.NewValue ![]() PasswordBox.PasswordChanged -= PasswordChanged PasswordBox passwordBox = sender as PasswordBox Private static void OnPasswordPropert圜hanged(DependencyObject sender, Private static void SetIsUpdating(DependencyObject dp, bool value) Return (bool)dp.GetValue(IsUpdatingProperty) Private static bool GetIsUpdating(DependencyObject dp) Public static void SetPassword(DependencyObject dp, string value) Return (string)dp.GetValue(PasswordProperty) Public static string GetPassword(DependencyObject dp) Return (bool)dp.GetValue(AttachProperty) Public static bool GetAttach(DependencyObject dp) Public static void SetAttach(DependencyObject dp, bool value) Private static readonly DependencyProperty IsUpdatingProperty =ĭependencyProperty.RegisterAttached("IsUpdating", typeof(bool), Typeof(bool), typeof(PasswordHelper), new PropertyMetadata(false, Attach)) Public static readonly DependencyProperty AttachProperty =ĭependencyProperty.RegisterAttached("Attach", New FrameworkPropertyMetadata(string.Empty, OnPasswordPropert圜hanged)) Public static readonly DependencyProperty PasswordProperty =ĭependencyProperty.RegisterAttached("Password", You can use attached properties to create a helper like this: public static class PasswordHelper Look at this blog post and see if it is helping you.Īpparently the link is dead now so here is the original solution (found here):
0 Comments
Leave a Reply. |