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
Wpf 绑定到资源文本文件_Wpf_Xaml_Data Binding_Text Files - Fatal编程技术网

Wpf 绑定到资源文本文件

Wpf 绑定到资源文本文件,wpf,xaml,data-binding,text-files,Wpf,Xaml,Data Binding,Text Files,我想将文本块绑定到作为资源编译的文本文件。有没有一种方法可以像绑定带有源属性和包uri的图像一样绑定它 <Image Source="pack://application:,,,/Properties/..."/> 好吧,你当然不能完全用同样的方法。如果您尝试以下方法: <TextBox Text="pack://application:,,,/Properties/..."/> 来自XAML的用法: <Window x:Class="WPF.MainW

我想将文本块绑定到作为资源编译的文本文件。有没有一种方法可以像绑定带有源属性和包uri的图像一样绑定它

<Image Source="pack://application:,,,/Properties/..."/>

好吧,你当然不能完全用同样的方法。如果您尝试以下方法:

<TextBox Text="pack://application:,,,/Properties/..."/>
来自XAML的用法:

<Window
    x:Class="WPF.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:wpf="clr-namespace:WPF">
    <TextBlock Text="{wpf:Text 'Assets/Data.txt'}" />
</Window>

当然,假设命名文本文件是一个资源:

进一步阅读:


我应该在那里处理IO/异常并忽略所有异常吗?我想是的。我看你没有机会这么做。
<Window
    x:Class="WPF.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:wpf="clr-namespace:WPF">
    <TextBlock Text="{wpf:Text 'Assets/Data.txt'}" />
</Window>