简体   繁体   中英

WPF Control binding sequence

I am writing my own WPF control.

Within the code of my control, how can I dictate the sequence/priority that the dependency properties bind in?

    <listselector:ChListSelector 
                Grid.Row="3" 
                SelectableGridLabelText="My Label"
                SelectedGridLabelText="My Other Label"
                SelectableItems="{Binding Path=SelectableItems, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                SelectedItems="{Binding Path=SelectedItems, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                SelectableGridColumns="{Binding Path=SelectableGridColumns, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                SelectedGridColumns="{Binding Path=SelectedGridColumns, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                />

I need to ensure that the two "GridColumns" properties are bound before the two "items" properties (as the GridColumns properties define how a couple of grids on my control display the items)

You don't really want to dictate the order of bindings to dependency properties. And I don't think there is any way to explicitly do that.

You should perform checking of the other property values in the PropertyChanged callbacks of your dependency properties and then perform actions depending on their states.

For instance: When the items properties are set, check to make sure that the grid properties are not null (or set using a flag) before updating the rest of the control. If they are are null, don't do anything. Subsequently when the grid properties are set, you may update the rest of the control. (You will want to also have checks for the items being not null in there as well.)

Or to simplify it, just have a single Setup() method for the control that null checks all of the required properties before executing and call that each time a property is set.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM