在2个控件之间共享内容 [英] Share content between 2 controls

查看:47
本文介绍了在2个控件之间共享内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码:

 <  网格 >  
< Grid.ColumnDefinitions >
< ColumnDefinition 宽度 = * / >
< ColumnDefinition 宽度 = 自动 / >
< ColumnDefinition 宽度 = * / >
< / Grid.ColumnDefinitions >
< ContentControl x:名称 = 主要内容 网格.Column = 0 >
部分内容
< / ContentControl >
< GridSplitter Grid.Column < span class =code-keyword> = 1 宽度 = 5 / >
< ContentControl 内容 = {Binding ElementName = MainContent,Path = Content} Grid.Column = 2 / >
< span class =code-keyword>< / Grid >







这显示了双方第一个ContentControl的内容。

如果我将Some content文本更改为任何控件,它仅在第二个ContentControl中显示内容,而不是在两者中。



有没有办法做到这一点?

解决方案

分享的一种方法是使用XAML 资源词典 http://blogs.msdn.com/b/wpfsldesigner/archive/2010/06 /03/creating-and-consuming-resource-dictionaries-in-wpf-and-silverlight.aspx [ ^ ]。



< dd> -SA


对解决方案1的评论中提出的问题与原始问题无关:

Itamarep问:

在我的情况下,我想显示2个显示相同内容的网络浏览器,当浏览一个时,它会在另一个中显示相同的结果。如果我将源连接到资源,它将同时打开同一页面浏览两次,更多,如果页面上的内部脚本更改显示,则URL不必更改含义它们将显示不同的页面(在相同的URL)

System.Windows.Controls.WebBrowser 不是 System.Windows.Controls.ContentControl ,它显示的媒体内容与 ContentControl的内容无关

http://msdn.microsoft.com/en-us/library/system.windows.controls.webbrowser.aspx [ ^ ]。



是不是这个问题的解决方案,特别是考虑到关于页面的内部脚本效果的最后一句琐碎?

浏览器URI已更改是1)您使用 Navigate 方法之一导航到其他URI; 2)当用户点击当前呈现的页面内的某些HTML导航控件(如锚点)时;换句话说,您可以使用浏览器页面外部和页面中的某些不同URL进行导航。在第一种情况下,只需从两个浏览器中调用相同的导航方法。



第二种情况只是一点点位不同且不对称:在一个浏览器实例中处理事件导航,并在其处理程序中,为另一个浏览器调用导航相应的浏览器实例。



首先,不要试图以互惠的方式在两个浏览器中处理此事件,以避免无限相互递归 http://en.wikipedia.org/wiki/Mutual_recursion [ ^ ] ...... :-)



< DD> -SA


I have the following code:

<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="*"/>
        <ColumnDefinition Width="Auto"/>
        <ColumnDefinition Width="*"/>
    </Grid.ColumnDefinitions>
    <ContentControl x:Name="MainContent" Grid.Column="0">
        Some content
    </ContentControl>
    <GridSplitter Grid.Column="1" Width="5"/>
    <ContentControl Content="{Binding ElementName=MainContent, Path=Content}" Grid.Column="2"/>
</Grid>




This shows the content of the first ContentControl in both sides.
If I change the "Some content" text to any control it shows the content only in the second ContentControl and not in both.

Is there any way to do this?

解决方案

One way to share is to use XAML resource dictionaries: http://blogs.msdn.com/b/wpfsldesigner/archive/2010/06/03/creating-and-consuming-resource-dictionaries-in-wpf-and-silverlight.aspx[^].

—SA


The question asked in the comment to Solution 1 has nothing to do with the original question:

Itamarep asked:

In my case, I want to display 2 web browsers that will display the same content and when browsing in one it will show the same results in the other. If I connect the source to a resource it will browse in both opening the same page twice, more than that, if an internal script on the page changes the display, the URL doesn't have to change meaning they will display different pages (under the same URL)

System.Windows.Controls.WebBrowser is not System.Windows.Controls.ContentControl, and the media content it shows has nothing to do with the content of ContentControl:
http://msdn.microsoft.com/en-us/library/system.windows.controls.webbrowser.aspx[^].

Isn't the resolution of this problem, especially taken into account the last clause about the effect of the page's "internal script" trivial?
The browser URI is changed is 1) you navigate to some other URI using one of the Navigate methods; 2) when a use clicks in some HTML navigation control (such as anchor) inside the page currently rendered; in other way, you can navigate using some different URL from outside the browser's page and from the page. In first case, simply call the same Navigate method from both browser.

The second case is just a little bit different and asymmetric: handle the event Navigating in one browser instance, and, in its handler, call Navigate for another browser instance accordingly.

First and foremost, don't try to handle this event in both browsers in reciprocal manner, to avoid "infinite" mutual recursion: http://en.wikipedia.org/wiki/Mutual_recursion[^]… :-)

—SA


这篇关于在2个控件之间共享内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆