如何仅使用 XAML 将资源从树视图绑定到 flowdocumentreader?

发布于 2024-12-22 00:27:59 字数 2367 浏览 2 评论 0原文

这次我正在开发一个帮助窗口迷你应用程序(包括在另一个项目中,即图像编辑应用程序)。

我有一个带有两列的网格,中间有一个网格分割器。左侧有一个包含多个节点的树视图(在 XAML 中设置),右侧有一个 flowdocumentreader。

我有大约 10 个资源词典,我在其中保存文档,每个节点一个,我想在我的 flowdocumentreader 中显示它们。我实际上不知道如何绑定它!有人知道我该怎么做吗?到目前为止我的代码(只添加了一个资源字典)

      <Window.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary x:Name="About"  Source="About.xaml"/>
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Window.Resources>
<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="auto"/>
        <ColumnDefinition Width="auto"/>
        <ColumnDefinition Width="500"/>
    </Grid.ColumnDefinitions>
    <GridSplitter HorizontalAlignment="Right" 
              VerticalAlignment="Stretch" 
              Grid.Column="1" ResizeBehavior="PreviousAndNext" ResizeDirection="Columns"
              Width="5" Background="#FFBCBCBC"/>
    <TreeView Width="250" Grid.Column="0" FontFamily="Segoe UI" FontSize="16">
        <TreeViewItem Header="Help">
            <TreeViewItem Header="About the application"></TreeViewItem>
            <TreeViewItem Header="Getting started"></TreeViewItem>
            <TreeViewItem Header="Images from Flickr"></TreeViewItem>
            <TreeViewItem Header="Images from the computer"></TreeViewItem>
            <TreeViewItem Header="Images from the browser"></TreeViewItem>
            <TreeViewItem Header="Editing">
                <TreeViewItem Header="Open and Save"></TreeViewItem>
                <TreeViewItem Header="Uploading"></TreeViewItem>
                <TreeViewItem Header="Crop"></TreeViewItem>
                <TreeViewItem Header="Resize"></TreeViewItem>
                <TreeViewItem Header="Filters"></TreeViewItem>
                <TreeViewItem Header="Adding text"></TreeViewItem>
                <TreeViewItem Header="Remove red eyes"></TreeViewItem>
            </TreeViewItem>
        </TreeViewItem>
    </TreeView>
    <FlowDocumentReader Grid.Column="2" >

    </FlowDocumentReader>
</Grid>

This time I am working on a help-window mini-application (to include in the other project, the imageediting application).

I have a grid with two columns and a gridsplitter inbetween. On the left I have a treeview with several nodes (set in XAML) and on the right a flowdocumentreader.

I have about 10 resourcedictionaries where I keep my documents, one for each node, that I want to display in my flowdocumentreader. I actually have no idea how to bind this! Anybody have an idea how I can do this? My code so far (only one resourcedictionary added)

      <Window.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary x:Name="About"  Source="About.xaml"/>
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Window.Resources>
<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="auto"/>
        <ColumnDefinition Width="auto"/>
        <ColumnDefinition Width="500"/>
    </Grid.ColumnDefinitions>
    <GridSplitter HorizontalAlignment="Right" 
              VerticalAlignment="Stretch" 
              Grid.Column="1" ResizeBehavior="PreviousAndNext" ResizeDirection="Columns"
              Width="5" Background="#FFBCBCBC"/>
    <TreeView Width="250" Grid.Column="0" FontFamily="Segoe UI" FontSize="16">
        <TreeViewItem Header="Help">
            <TreeViewItem Header="About the application"></TreeViewItem>
            <TreeViewItem Header="Getting started"></TreeViewItem>
            <TreeViewItem Header="Images from Flickr"></TreeViewItem>
            <TreeViewItem Header="Images from the computer"></TreeViewItem>
            <TreeViewItem Header="Images from the browser"></TreeViewItem>
            <TreeViewItem Header="Editing">
                <TreeViewItem Header="Open and Save"></TreeViewItem>
                <TreeViewItem Header="Uploading"></TreeViewItem>
                <TreeViewItem Header="Crop"></TreeViewItem>
                <TreeViewItem Header="Resize"></TreeViewItem>
                <TreeViewItem Header="Filters"></TreeViewItem>
                <TreeViewItem Header="Adding text"></TreeViewItem>
                <TreeViewItem Header="Remove red eyes"></TreeViewItem>
            </TreeViewItem>
        </TreeViewItem>
    </TreeView>
    <FlowDocumentReader Grid.Column="2" >

    </FlowDocumentReader>
</Grid>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

回心转意 2024-12-29 00:27:59

您可以使用节点的 Tag 属性来定义要加载的字符串值。
然后对所选节点的标签进行绑定。

如果您随后使用转换器,您可以从 file/res.Dict 或其他内容加载文档内容:

  <TreeView x:Name="documentTreeView" Width="250" Grid.Column="0" FontFamily="Segoe UI" FontSize="16">
    <TreeViewItem Header="Help">
      <TreeViewItem 
         Header="About the application" 
         Tag="ResDict1.xaml"></TreeViewItem>

...

  <FlowDocumentReader Document="{Binding ElementName=documentTreeView, Path=SelectedItem.Tag, Converter={StaticResource stringToFlowDocumentConverter}}"  Grid.Column="2" />

You could use the Tag property of the nodes to define a string value to be loaded.
Then do a binding on the selected Node's Tag.

If you then use a converter you can load your document content from file/res.Dict or whatever:

  <TreeView x:Name="documentTreeView" Width="250" Grid.Column="0" FontFamily="Segoe UI" FontSize="16">
    <TreeViewItem Header="Help">
      <TreeViewItem 
         Header="About the application" 
         Tag="ResDict1.xaml"></TreeViewItem>

....

  <FlowDocumentReader Document="{Binding ElementName=documentTreeView, Path=SelectedItem.Tag, Converter={StaticResource stringToFlowDocumentConverter}}"  Grid.Column="2" />
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文