user22527635
user22527635

Reputation: 1

WPF - How to set Bound property directly in the XAML file, with preset fixed values?

I would like to know if it is possible to set a BOUND int variable/property in the XAML, giving it a fixed value written directly in the XAML file, in a control that behaves like a button:

click from btn1 set to 1, click from btn2 set to 2, ...

At the moment the only similar thing I use is a combobox with default values:

<ComboBox Text="{Binding TestInt, UpdateSourceTrigger=PropertyChanged}"
          SelectedValuePath="Content">

    <ComboBoxItem IsSelected="True" Content="0"/>
    <ComboBoxItem IsSelected="True" Content="1"/>
    <ComboBoxItem IsSelected="True" Content="2"/>
    <ComboBoxItem IsSelected="True" Content="3"/>

</ComboBox>

I tried with the "Command" of the Button object, but it seems very resource-intensive and complicated due to the CanExecute() task.

I'd like it to be manageable only in the XAML, so that I can BIND several controls to the same variable, each of which sets a different value, but I don't know which control to use for this purpose

Thanks in advance!

Upvotes: 0

Views: 65

Answers (0)

Related Questions