Get user interface object from data object

I have a class (MockWI) in which I defined the following DataTemplate in app.xml

<DataTemplate DataType="{x:Type local:MockWI}">
    <Button Content="{Binding Name}"/>
</DataTemplate>

In my code, I need to find an interface object that has a MockWI instance.

Now I am doing this:

Button elt = new Button { Content = myMockWI};

But that gives me a button on a button.

I want to just get a button called MockWI called myMockWI. Something like that:

Button elt = GetUIControlFromVar(myMockWI);

Is there any way to do this?


Adding additional code to display context:

    public UIElement GetVisualFeedback(IDataObject obj)
    {
        MockWI test = ExtractElement(obj);

        // Since Content is set to a MockWI I get a button in a button.
        Button elt = new Button{ Content = test, Opacity = 0.5, IsHitTestVisible = false };

        DoubleAnimation anim = new DoubleAnimation(0.75, new Duration(TimeSpan.FromMilliseconds(500)))
                                   {
                                       From = 0.25,
                                       AutoReverse = true,
                                       RepeatBehavior = RepeatBehavior.Forever
                                   };
        elt.BeginAnimation(UIElement.OpacityProperty, anim);

        return elt;
    }
+1
source share
2 answers

, , UI , , .

(ItemsControl, ListBox, ListView, DataGrid ..), ItemsControl.ItemContainerGenerator.GetContainerFromItem.

+2

, (, , ).

- DataTemplate, EventTrigger -s EnterActions/ExitActions, , .

(Storyboard) XAML / (, Blend).

+1

Source: https://habr.com/ru/post/1730967/


All Articles