dependency-properties

WPF: PropertyChangedCallback triggered only once

僤鯓⒐⒋嵵緔 提交于 2019-11-29 18:27:00
问题 I have a user control, which exposes a DependencyProperty called VisibileItems Every time that property gets updated, i need to trigger another event. To achieve that, i added a FrameworkPropertyMetadata with PropertyChangedCallback event. For some reason, this event gets called only once, and doesn't trigger the next time VisibleItems is changed. XAML: <cc:MyFilterList VisibleItems="{Binding CurrentTables}" /> CurrentTables is a DependencyProperty on MyViewModel. CurrentTables gets changed

Binding between Usercontrol with listbox and parent control (MVVM)

痞子三分冷 提交于 2019-11-29 17:57:21
I have a UserControl which contains a listbox and few buttons. <UserControl x:Class="ItemControls.ListBoxControl" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"> <Grid> <ListBox:ExtendedListBox SelectionMode="Single" ItemsSource="{Binding LBItems}" Height="184"> <ListBox.ItemTemplate> <DataTemplate> <CheckBox Content="{Binding}"/> </DataTemplate> </ListBox.ItemTemplate> </ListBox> <Button

Data binding dependency property to data object

我的未来我决定 提交于 2019-11-29 15:28:40
I have a DependencyObject with a DependencyProperty: public class DependencyObjectClass: DependencyObject { public static DependencyProperty BooleanValueProperty = DependencyProperty.Register("BooleanValue", typeof (bool), typeof (DependencyObjectClass)); public bool BooleanValue { get { return (bool)GetValue(BooleanValueProperty); } set { SetValue(BooleanValueProperty, value); } } } I also have my data source class: public class DataSource: INotifyPropertyChanged { private bool _istrue; public bool IsTrue { get { return _istrue; } set { _istrue = value; if (PropertyChanged != null)

How does Xaml create the string to BitmapImage value conversion when binding to Image.Source?

徘徊边缘 提交于 2019-11-29 12:44:57
I'm creating an Image.Source - String binding in code like: var newBinding = new System.Windows.Data.Binding() { Path = new PropertyPath("MyImageUrl") }; BindingOperations.SetBinding(attachedObject, Image.SourceProperty, newBinding); This approach works well for, for example, TextBlock.TextProperty - String bindings, but for the Image.Source - String I ideally would like the Binding to automatically insert a conversion for me - in the same way that the Xaml binding does when I use: <Image Source="{Binding ImageUrl}" /> I realise I can add my own converter to mimic the Xaml binding behaviour,

Knowing if a DependencyProperty has not been set in XAML

天涯浪子 提交于 2019-11-29 09:39:14
问题 I have a control, which exposes a DP called PlacementTarget (it's bound to a child Popup FWIW). What I want to do is if PlacementTarget is not set in XAML, then (the control will) set it to the Window the control is in. When I say 'not set' I don't mean simply 'is null' (this allows the user dev to set PlacementTarget to null, and the control won't auto set it to the Window). I have a field called placementTargetIsSet, which I set to true in the Change event handler public readonly static

Why do I get a DependencyProperty.UnsetValue when converting a value in a MultiBinding?

♀尐吖头ヾ 提交于 2019-11-29 09:04:26
I have an extremely simple IMultiValueConverter that simply OR's two values. In the example below, I want to invert the first value using an equally simple boolean inverter. <MultiBinding Converter="{StaticResource multiBoolToVis}"> <Binding Path="ConditionA" Converter="{StaticResource boolInverter}"/> <Binding Path="ConditionB"/> </MultiBinding> and the inverter: public class BoolInverterConverter : IValueConverter { #region IValueConverter Members public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { if (value is bool) { return !(

Dependency Property assigned with value binding does not work

▼魔方 西西 提交于 2019-11-29 07:29:08
问题 I have a usercontrol with a dependency property. public sealed partial class PenMenu : UserControl, INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; protected void OnPropertyChanged(string propertyName) { if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); } } public bool ExpandCollapse { get { return false; } set { //code } } public static readonly DependencyProperty ExpandCollapseProperty = DependencyProperty

Using enum as a dependency property in WPF

假如想象 提交于 2019-11-29 07:08:30
I try to use enum type as a dependency property in my custom control, but always get an error: public enum PriceCategories { First = 1, Second = 2, Third = 3, Fourth = 4, Fifth = 5, Sixth = 6 } public static readonly DependencyProperty PriceCatProperty = DependencyProperty.Register("PriceCat", typeof(PriceCategories), typeof(CustControl), new PropertyMetadata(PriceCategories.First)); }; public PriceCategories PriceCat // here I get an error "Expected class, delegate, enum, interface or struct" { get { return (PriceCategories)GetValue(PriceCatProperty); } set { SetValue(PriceCatProperty, value)

Arranging collection items in a grid

*爱你&永不变心* 提交于 2019-11-29 04:33:58
I would like to arrange items of a collection in a grid with a specific number of columns and rows (say 4x6). Each item exposes the dependency properties (integer) X and Y and should be placed in the relevant cell of the grid. Note that the collection can change during runtime which should update the grid items. I couldn't find any good solution. But maybe it is even possible without using the code-behind? Don't mind conversion or something. This stuff changes anyway. The used collection class isn't important. (You can choose one.) How can I solve this problem? Any appropriate suggestions

Is there a way to specify a custom dependency property's default binding mode and update trigger?

谁都会走 提交于 2019-11-29 04:24:10
问题 I would like to make it so that, as default, when I bind to one of my dependency properties the binding mode is two-way and update-trigger is property changed. Is there a way to do this? Here is an example of one of my dependency properties: public static readonly DependencyProperty BindableSelectionLengthProperty = DependencyProperty.Register( "BindableSelectionLength", typeof(int), typeof(ModdedTextBox), new PropertyMetadata(OnBindableSelectionLengthChanged)); 回答1: When registering the