首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >停用自动SVI- ScatterView换行

停用自动SVI- ScatterView换行
EN

Stack Overflow用户
提问于 2014-03-13 00:27:39
回答 1查看 47关注 0票数 0

我尝试在PixelSense-Project中使用MVVM。我将一些元素绑定到ScatterView:

代码语言:javascript
复制
<s:ScatterView x:Name="MainScatterView" ItemTemplateSelector="{DynamicResource myDataTemplateSelector}" ItemsSource="{Binding Path=MainMenus}"/>

我定义了一些DataTemplates:

代码语言:javascript
复制
    <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>

如您所见,我尝试(例如)将height-property绑定到ViewModel。

它不工作,因为我的SVI (ScatterViewItem)将自动被另一个SVI包装。这是由ScatterView完成的。我现在的问题是:我怎样才能停用它,或者你知道一个解决方法?

感谢您对我的帮助;-)

EN

回答 1

Stack Overflow用户

发布于 2014-03-13 22:44:36

我找到了一个变通办法...它不是最好的,但它是有效的:)也许有人也会有这个问题:

我从模板中删除了周围的事件,并添加了ScatterViewItem -ScatterViewItem:

代码语言:javascript
复制
    <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>

其余部分在后面的代码中:

代码语言:javascript
复制
    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);
    }

如果您知道更好的解决方案:请让我知道;)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22357849

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档