小编mar*_*s s的帖子

如何绑定到ContentControl的Datatemplate中的数据

我有以下简化示例:

    <Window x:Class="TemplateBinding.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            Title="MainWindow" Height="350" Width="525">
        <Window.Resources>
            <ResourceDictionary>
                <ResourceDictionary.MergedDictionaries>
                    <ResourceDictionary
                            Source="pack://application:,,,/TemplateBinding;component/PersonTemplate.xaml" />
                </ResourceDictionary.MergedDictionaries>
            </ResourceDictionary>
        </Window.Resources>
        <Grid>
            <ContentControl ContentTemplate="{StaticResource PersonTemplate}" />
        </Grid>
    </Window>
Run Code Online (Sandbox Code Playgroud)

附:

    <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

        <DataTemplate x:Key="PersonTemplate">
            <Border Width="100" Height="100" Background="RosyBrown">
                <TextBlock Text="{Binding Path=FirstName}" VerticalAlignment="Center" TextAlignment="Center"/>
            </Border>
        </DataTemplate>

    </ResourceDictionary>
Run Code Online (Sandbox Code Playgroud)

作为我的DataTemplate在一个单独的ResourceDictionary文件中.

我在我的MainWindow的Construcor中设置了我的DataContext,并通过显示如下的第一个名称来验证它:<ContentControl Grid.Row="1" Content="{Binding FirstName}"/>.

在另一个场景中,我使用DataTemplate与我在DataTemplate中以ListBox完全相同的方式进行绑定,它只是起作用.

我知道DataTemplate除了绑定之外正在工作,因为它正确显示了大小和背景颜色.

我究竟做错了什么?我的DataTemplate中的绑定如何看?

data-binding wpf datatemplate resourcedictionary contentcontrol

26
推荐指数
1
解决办法
3万
查看次数

Android复制并粘贴到任何应用程序中的任何文本字段

我正在开发一个商业用途的应用程序,后台服务通过蓝牙从RFID阅读器获取转发器号码(动物).

处理完收到的号码后,我想把它发送到剪贴板并将其粘贴到目前正在进行的任何应用程序的焦点文本字段中,在我的情况下是浏览器应用程序.

我已经在2013年找到了一个类似的问题,但现在还没有接受.该问题的所有答案都解释了如何使用ClipboardManager在开发的应用程序中复制和粘贴代码,但在评论中澄清时,这并不是问题的意思.

我能想象到的最简单的场景是在Android设备上模拟粘贴动作.我宁愿不需要安装第三方应用程序.

java android copy-paste

10
推荐指数
2
解决办法
2617
查看次数