Question

I have ItemsControl with DataTemplateSelector, with buttons like:

 <DataTemplate x:Key="buttonTemplate">
            <Button>
                <Button.Content>
                    <Image Source="sample.png" Height="{Binding height}" Width="{Binding width}" Stretch="Fill" HorizontalAlignment="Center" VerticalAlignment="Center" />
                </Button.Content>
                <Button.RenderTransform>
                    <RotateTransform Angle="{Binding angle}" />
                </Button.RenderTransform>
            </Button>
        </DataTemplate>

I'm filling my ItemsControl with storedprocedure, so elements are from my ObservableCollection.

public class rObject
{
    public int elementID { get; set; }
    public string elementType { get; set; }
    public string elementName { get; set; }
    public Thickness thick { get; set; }
    public int width { get; set; }
    public int height { get; set; }
    public int angle { get; set; }
}

Buttons have methods to move them (which change thick), resize, rotate etc. So for example there is button with properties:

1*) angle = 0, thick = 0,0,0,0, width = 50, height = 50, elemetID = 1 etc.

Now i move button little bit and resize, so thick would be for example 10,10,10 10 and height=width = 100.

What I'd like to do now is press save button, which will save new data to database. Problem is that, in my ObservableCollection my button still have properties like in 1*.

So is there any way to get element which is Button, not rObject from my ItemsControl?

Thanks in advance!

Was it helpful?

Solution

What you need is two way binding of the source. i.e. If either one of the property changes the other one automatically updates.

So you would need to bind like this -

 Height="{Binding Path=height, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"

Have a look at this article - Two-Way Databinding in WPF

You would need to implement INotifyPropertyChanged Interface on rObject Class to reflect any change to the UI. Do this only if you need it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top