none
gridview 虚拟化导致已绑定内容发生变化,请指教。 RRS feed

  • 问题

  • 我在girdview item绑定了 类,
    模版里面包含了一个richtextblock。在绑定时会对内容进行逻辑处理并显示。
    可是在滑动gridview的时候,

    item上原先的内容就会发生变化,

    要怎么解决?
    2013年10月7日 6:55

答案

  • 您好:

    如果您没有将绑定的内容注册为依赖属性并且每次内容改变时都会触发oncontentchange事件的话,虚拟化应该是不会影响item值的改变。您所说的交互操作和html解析其实在ItemModel类里面都能够实现。还有一种影响性能的方法就是您可以将gridview默认的虚拟化给禁止掉!


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey. Thanks<br/> MSDN Community Support<br/> <br/> Please remember to &quot;Mark as Answer&quot; the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    2013年10月9日 6:12
    版主

全部回复

  • Hi,

    item内容具体是指什么内容?您的问题很难重现所以我们这里不好测试,您能否发一个简单的Project在SkyDrive上,我们好测试一下!


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey. Thanks<br/> MSDN Community Support<br/> <br/> Please remember to &quot;Mark as Answer&quot; the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    2013年10月8日 5:21
    版主
  • http://sdrv.ms/15jdwlZ   这个是demo的下载地址, 可以看到在滑动gridview的时候内容就一直变化,知道是虚拟化造成的,要怎么解决呢?
    2013年10月8日 6:08
  • Hi,

    item内容具体是指什么内容?您的问题很难重现所以我们这里不好测试,您能否发一个简单的Project在SkyDrive上,我们好测试一下!


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey. Thanks<br/> MSDN Community Support<br/> <br/> Please remember to &quot;Mark as Answer&quot; the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    http://sdrv.ms/15jdwlZ   这个是demo的下载地址, 可以看到在滑动gridview的时候内容就一直变化,知道是虚拟化造成的,要怎么解决呢?
    2013年10月8日 6:18
  • Hi,

    当您滑动Gridview的时候,因为系统会自动将GridView中内容清空并且重新加载,所以您项目里面定义的OnContentChanged在每次GridView滑动的时候都会触发,且item里面的内容也会跟着改变。您为什么要将Content设置为依赖属性呢,是不是您有特别的要求一定要用RichTextBlockHelper这种方式呢?如果不是的话您可以直接在RichTextBlock中绑定Content,您可以在UserCtr.xaml页面作如下修改:

    <Grid Background="Blue" Width="300" Height="300">
            <Grid.RowDefinitions>
                <RowDefinition Height="auto"></RowDefinition>
                <RowDefinition></RowDefinition>
            </Grid.RowDefinitions>
            <TextBlock Grid.Row="0" FontSize="20" Foreground="Red">
                <Run Text="No."></Run>
                <Run Text="{Binding Index}"></Run>
            </TextBlock>
            <RichTextBlock  Grid.Row="1" >
                <Paragraph>
                    <InlineUIContainer>
                        <TextBlock Text="{Binding Content}"/>
                    </InlineUIContainer>
                </Paragraph>
            </RichTextBlock>
        </Grid>


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey. Thanks<br/> MSDN Community Support<br/> <br/> Please remember to &quot;Mark as Answer&quot; the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    2013年10月8日 9:57
    版主
  • Hi,

    当您滑动Gridview的时候,因为系统会自动将GridView中内容清空并且重新加载,所以您项目里面定义的OnContentChanged在每次GridView滑动的时候都会触发,且item里面的内容也会跟着改变。您为什么要将Content设置为依赖属性呢,是不是您有特别的要求一定要用RichTextBlockHelper这种方式呢?如果不是的话您可以直接在RichTextBlock中绑定Content,您可以在UserCtr.xaml页面作如下修改:

    <Grid Background="Blue" Width="300" Height="300">
            <Grid.RowDefinitions>
                <RowDefinition Height="auto"></RowDefinition>
                <RowDefinition></RowDefinition>
            </Grid.RowDefinitions>
            <TextBlock Grid.Row="0" FontSize="20" Foreground="Red">
                <Run Text="No."></Run>
                <Run Text="{Binding Index}"></Run>
            </TextBlock>
            <RichTextBlock  Grid.Row="1" >
                <Paragraph>
                    <InlineUIContainer>
                        <TextBlock Text="{Binding Content}"/>
                    </InlineUIContainer>
                </Paragraph>
            </RichTextBlock>
        </Grid>


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey. Thanks<br/> MSDN Community Support<br/> <br/> Please remember to &quot;Mark as Answer&quot; the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Hi,多谢您的帮忙。我是在richitextbox里面要做一些处理的。从服务端返回的都是html数据,我需要解析一下才能显示的。这样有其他方法解决这个问题吗? 
    2013年10月8日 9:59
  • Hi,

    您如果是想显示的话,您可以先将服务端返回的数据先解析然后再赋值给ItemModel类的content属性,最后RichTextBlock也可以绑定到解析好的内容上并显示,我觉得这样子的话也能达到您的要求,不用在RichTextBlockHelper上定义一个依赖属性且可以不用将RichTextBlock与RichTextBlockHelper相关联!


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey. Thanks<br/> MSDN Community Support<br/> <br/> Please remember to &quot;Mark as Answer&quot; the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    2013年10月9日 3:45
    版主
  • Hi,

    您如果是想显示的话,您可以先将服务端返回的数据先解析然后再赋值给ItemModel类的content属性,最后RichTextBlock也可以绑定到解析好的内容上并显示,我觉得这样子的话也能达到您的要求,不用在RichTextBlockHelper上定义一个依赖属性且可以不用将RichTextBlock与RichTextBlockHelper相关联!


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make  community forums a great place.
    Click HERE to participate the survey. Thanks<br/> MSDN Community Support<br/> <br/> Please remember to &quot;Mark as Answer&quot; the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    不仅仅是显示,要有一些交互操作的。而且这个只是一个简单的demo。我在其他地方也有这方面的运用需求。比如我在gridviewitem里面用到一个listbox or listview 里面的数据是动态请求的。然后我在控件loaded事件里面去请求并加载,然后在滑动的时候也会出现乱七八糟的现象,这个问题跟这种是一个问题。也是虚拟化引起的。

    Ps:跟loaded事件无关。只请求一次也会出现这种情况的。

    2013年10月9日 3:50
  • 您好:

    如果您没有将绑定的内容注册为依赖属性并且每次内容改变时都会触发oncontentchange事件的话,虚拟化应该是不会影响item值的改变。您所说的交互操作和html解析其实在ItemModel类里面都能够实现。还有一种影响性能的方法就是您可以将gridview默认的虚拟化给禁止掉!


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey. Thanks<br/> MSDN Community Support<br/> <br/> Please remember to &quot;Mark as Answer&quot; the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    2013年10月9日 6:12
    版主
  • 您好:

    如果您没有将绑定的内容注册为依赖属性并且每次内容改变时都会触发oncontentchange事件的话,虚拟化应该是不会影响item值的改变。您所说的交互操作和html解析其实在ItemModel类里面都能够实现。还有一种影响性能的方法就是您可以将gridview默认的虚拟化给禁止掉!


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey. Thanks<br/> MSDN Community Support<br/> <br/> Please remember to &quot;Mark as Answer&quot; the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.


    我监测了oncontentchange,不会每次都触发他的。另外,肿么禁止呢?
    2013年10月9日 6:14
  • 您好:

    oncontentchange并不是每次都触发的,只有当content内容变化的时候才会触发,您可以用以下代码来禁止gridview虚拟化:

    <GridView x:Name="griddemo">
            <GridView.ItemsPanel>
                <ItemsPanelTemplate>
                    <VariableSizedWrapGrid/>
                </ItemsPanelTemplate>
            </GridView.ItemsPanel>
            <GridView.ItemTemplate>
                <DataTemplate>
                    <local:UserCtrl />
                </DataTemplate>
            </GridView.ItemTemplate>
        </GridView>


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey. Thanks<br/> MSDN Community Support<br/> <br/> Please remember to &quot;Mark as Answer&quot; the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    2013年10月9日 6:18
    版主