读书人

|ZYCWPF| 为RichTextBox添加查找替换功

发布时间: 2012-12-26 14:39:28 作者: rapoo

|ZYCWPF| 为RichTextBox添加查找替换功能,为什么我绑定的控件得不到控件对像,而是得到一个int 0 谢谢
原贴:http://bbs.csdn.net/topics/390319147
XAML改为:



<Window x:Class="_0_0_测试.MainTest"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:zc="clr-namespace:Z.Core.WPF.Controls;assembly=Z.Core.WPF"
xmlns:local="clr-namespace:_0_0_测试"
Title="MainTest" Height="600" Width="600">
<StackPanel>
<Button Content="选择内容" Click="Button_Click_1" />
<zc:ZRichTextBox x:Name="richTextBox"
Height="200" Margin="10,10,10,5"
ToolbarBackground="#FFD2CB84" ToolbarBorderBrush="#FFC6BE75" ToolbarBorderThickness="1,1,1,0"
CodeControlsVisibility="Visible" >
<zc:ZRichTextBox.Resources>
<zc:IEditorConverter x:Key="IEditorConverter" />
<zc:FindReplaceMgr x:Key="FRep"
InterfaceConverter="{StaticResource IEditorConverter}"
CurrentEditor="{Binding RelativeSource={RelativeSource AncestorType={x:Type zc:ZRichTextBox}}}"
AllowReplace="True" />
</zc:ZRichTextBox.Resources>
<zc:ZRichTextBox.CommandBindings>
<local:StaticResourceEx ResourceKey="FRep" Path="FindBinding" />
<local:StaticResourceEx ResourceKey="FRep" Path="ReplaceBinding" />
<local:StaticResourceEx ResourceKey="FRep" Path="FindNextBinding" />
</zc:ZRichTextBox.CommandBindings>
<zc:ZRichTextBox.InputBindings>
<KeyBinding Key="F3" Modifiers="Shift" Command="Search" CommandParameter="something" />


</zc:ZRichTextBox.InputBindings>
</zc:ZRichTextBox>
</StackPanel>
</Window>


CurrentEditor="{Binding RelativeSource={RelativeSource AncestorType={x:Type zc:ZRichTextBox}}}"
我想让这个CurrentEditor绑定为这个ZRichTextBox,但我上面的写法,最终得到的是 int 0
在:Z.Core.WPF\Controls\FindReplaceDialog.xaml.cs 661中
return InterfaceConverter.Convert(CurrentEditor, typeof(IEditor), null, CultureInfo.CurrentCulture) as IEditor;
CurrentEditor 的值为 0
这是为什么
如何正确绑定
谢谢

PS:上贴回复中的:RelativeSource Self的话绑定的是FindReplaceMgr而不是我要的ZRichTextBox
谢谢
[解决办法]
当前窗体也是属于visual tree的,也不能在resources里写绑定,同样要在后台写
[解决办法]
类型都不同,怎么绑定上的。好奇怪。

需要编写一个事件,把窗体传进来,而不能直接绑定到资源。

读书人网 >C#

热点推荐