user3411637
user3411637

Reputation: 1

deactivate automatic SVI-wrapping of ScatterView

i try to use MVVM for a PixelSense-Project. I bound some elements to the ScatterView:

<s:ScatterView x:Name="MainScatterView" ItemTemplateSelector="{DynamicResource myDataTemplateSelector}" ItemsSource="{Binding Path=MainMenus}"/>

And i defined some DataTemplates:

    <DataTemplate x:Key="ActivityTemplate">
        <s:ScatterViewItem Loaded="ScatterViewItem_Loaded">
            <TextBlock Text="{Binding Path=Text}" />
        </s:ScatterViewItem>
    </DataTemplate>

    <DataTemplate x:Key="MainMenuTemplate">
        <s:ScatterViewItem Height="{Binding Path=Size, Mode=TwoWay}" Width="{Binding Path=Size, Mode=TwoWay}">
            <TextBlock/>
        </s:ScatterViewItem>
    </DataTemplate>

As you can see, i try to bind (for example) the height-property to the ViewModel.

It is not working, because my SVI (ScatterViewItem) will automatically be wrapped by another SVI. This is done by the ScatterView. My question is now: How can i deactivate this, or do you know a workaround?

thx for helping me ;-)

Upvotes: 0

Views: 58

Answers (1)

user3411637
user3411637

Reputation: 1

I found a workaround... it's not the nicest, but it works :) Perhaps somebody will have this problem too:

I removed the surrounding ScatterViewItem from the Template and added the Loaded-event:

    <DataTemplate x:Key="ActivityTemplate">
            <TextBlock Text="{Binding Path=Text}" Loaded="TextBlock_Loaded"/>
    </DataTemplate>

    <DataTemplate x:Key="MainMenuTemplate">
            <TextBlock Width="20" Height="20" Text="Hallo" Loaded="TextBlock_Loaded"/>
    </DataTemplate>

the rest is in the code behind:

    private void TextBlock_Loaded(object sender, RoutedEventArgs e)
    {
        //Get the sourrounding ScatterViewItem via the VisualTree
        System.Windows.Media.Visual parent = (System.Windows.Media.Visual)VisualTreeHelper.GetParent((System.Windows.Media.Visual)sender);
        while (!(parent is ScatterViewItem))
        {
            parent = (System.Windows.Media.Visual)VisualTreeHelper.GetParent((System.Windows.Media.Visual)parent);
        }

        //the current parent is the surrounding SVI
        ScatterViewItem svi = parent as ScatterViewItem;

        //Bind the properties to the SVI
        Binding myBinding = new Binding("Size");
        myBinding.Source = svi.DataContext;
        svi.SetBinding(ScatterViewItem.HeightProperty, myBinding);
        svi.SetBinding(ScatterViewItem.WidthProperty, myBinding);
    }

if you know a better solution: please let me know ;)

Upvotes: 0

Related Questions