Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/256.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/neo4j/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# ListBox绑定中的扩展WPF工具箱富文本框_C#_Wpf_Data Binding_Richtextbox_Observablecollection - Fatal编程技术网

C# ListBox绑定中的扩展WPF工具箱富文本框

C# ListBox绑定中的扩展WPF工具箱富文本框,c#,wpf,data-binding,richtextbox,observablecollection,C#,Wpf,Data Binding,Richtextbox,Observablecollection,我试图在列表视图中绑定RichTextBox,但没有效果。如果我不在listview中包装RichTextBox,只将其分配给类,那么它就可以正常工作。但是,只要我尝试分配给列表视图,它就不会显示文本,而是显示适当数量的项目 例如: <ListBox Name="lstBook" ItemsSource="{Binding}" Width="auto"> <ListBox.ItemTemplate> &

我试图在列表视图中绑定RichTextBox,但没有效果。如果我不在listview中包装RichTextBox,只将其分配给类,那么它就可以正常工作。但是,只要我尝试分配给列表视图,它就不会显示文本,而是显示适当数量的项目

例如:

    <ListBox Name="lstBook" ItemsSource="{Binding}" Width="auto">           
        <ListBox.ItemTemplate>
            <DataTemplate>
                <StackPanel Orientation="Horizontal">
                    <extToolkit:RichTextBox Margin="5" 
                                BorderBrush="Gray" Padding="1"
                                Text="{Binding Path=Notes, Mode=OneWayToSource, UpdateSourceTrigger=PropertyChanged}" 
                                ScrollViewer.VerticalScrollBarVisibility="Auto"
                                Height="100" 
                                Width="425">
                        <extToolkit:RichTextBox.TextFormatter>
                            <extToolkit:RtfFormatter />
                        </extToolkit:RichTextBox.TextFormatter>
                    </extToolkit:RichTextBox>                       
                </StackPanel>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>
要填充的代码:

        ObservableCollection<Data> datas = new ObservableCollection<Data>();

        Data d = new Data
                     {
                         Notes =
                             @"{\rtf1\ansi\ansicpg1252\uc1\htmautsp\deff2{\fonttbl{\f0\fcharset0 Times New Roman;}{\f2\fcharset0 Segoe UI;}}{\colortbl\red0\green0\blue0;\red255\green255\blue255;}\loch\hich\dbch\pard\plain\ltrpar\itap0{\lang1033\fs18\f2\cf0 \cf0\ql{\f2 {\ltrch This is the }{\b\ltrch RichTextBox}\li0\ri0\sa0\sb0\fi0\ql\par}}}"
                     };

        datas.Add(d);

        d = new Data();
        d.Notes = @"{\rtf1\ansi\ansicpg1252\uc1\htmautsp\deff2{\fonttbl{\f0\fcharset0 Times New Roman;}{\f2\fcharset0 Segoe UI;}}{\colortbl\red0\green0\blue0;\red255\green255\blue255;}\loch\hich\dbch\pard\plain\ltrpar\itap0{\lang1033\fs18\f2\cf0 \cf0\ql{\f2 {\ltrch This is the }{\b\ltrch RichTextBox}\li0\ri0\sa0\sb0\fi0\ql\par}}}";

        datas.Add(d);

        lstBook.ItemsSource = datas;
ObservableCollection数据=新的ObservableCollection();
数据d=新数据
{
注释=
@“{\rtf1\ansi\ansicpg1252\uc1\htmautsp\deff2{\fonttbl{\f0\fcharset0 Times New Roman;}{\f2\fcharset0 Segoe UI;}}{\colortbl\red0\green0\BLUEN0;\red255\green255\BLUEN255;}\loch\hich\dbch\pard\plain\ltrpar\itap0{\lang1033\fs18\f2\cf0\cf0\cf0\ql{\ltrch这是}\LTRCH0\LTRIB0\LTBARCH0\FRICH0\FRIEN0}\FRICH0\FRICH0\FRICH0}\FRICH0\FRICH0\FRIEN0}”
};
添加数据(d);
d=新数据();
d、 Notes=@“{\rtf1\ansi\ansicpg1252\uc1\htmautsp\deff2{\fonttbl{\f0\fcharset0 Times New Roman;}{\f2\fcharset0 Segoe UI;}}{\colortbl\red0\green0\BLUEN0;\red255\green255\BLUEN255;}\loch\hich\dbch\pard\plain\ltrpar\itap0{\1033\fs18\f2\cf0\cf0\cf0\ql{\f2\ltrch这是}\LTB\LTRICH0\LTRICH0\LTBAR}\LTBAR}\;
添加数据(d);
lstBook.ItemsSource=数据;
我错过了什么?列表框显示两条记录,但Rtf框中不显示文本


谢谢…

您的绑定模式是
OneWayToSource
。本例中的源是
Data
实例,因此您将数据从
RichTextBox
推回到
Notes
属性,而不是另一个方向


将绑定模式更改为单向或双向,具体取决于您试图实现的目标。

数据
不是一个正确的词<代码>数据已经是复数。但这可能不是你问题的答案。
        ObservableCollection<Data> datas = new ObservableCollection<Data>();

        Data d = new Data
                     {
                         Notes =
                             @"{\rtf1\ansi\ansicpg1252\uc1\htmautsp\deff2{\fonttbl{\f0\fcharset0 Times New Roman;}{\f2\fcharset0 Segoe UI;}}{\colortbl\red0\green0\blue0;\red255\green255\blue255;}\loch\hich\dbch\pard\plain\ltrpar\itap0{\lang1033\fs18\f2\cf0 \cf0\ql{\f2 {\ltrch This is the }{\b\ltrch RichTextBox}\li0\ri0\sa0\sb0\fi0\ql\par}}}"
                     };

        datas.Add(d);

        d = new Data();
        d.Notes = @"{\rtf1\ansi\ansicpg1252\uc1\htmautsp\deff2{\fonttbl{\f0\fcharset0 Times New Roman;}{\f2\fcharset0 Segoe UI;}}{\colortbl\red0\green0\blue0;\red255\green255\blue255;}\loch\hich\dbch\pard\plain\ltrpar\itap0{\lang1033\fs18\f2\cf0 \cf0\ql{\f2 {\ltrch This is the }{\b\ltrch RichTextBox}\li0\ri0\sa0\sb0\fi0\ql\par}}}";

        datas.Add(d);

        lstBook.ItemsSource = datas;