WPF:元素绑定

时间:2013-04-09 13:45:37

标签: wpf vb.net

我需要将librarybar项目的名称链接到一个单独的文本块中进行同步,以确定我要拖动的内容等。

无论如何,我可以从这里绑定内容文本:

<my:LibraryBar 
            HorizontalAlignment="Center" 
            Name="libcont" 
            VerticalAlignment="Top" 
            Background="{x:Null}"
            ItemsSource="{Binding}"  
            Width="850" 
            Height="250"

            >
            <my:LibraryBar.ItemTemplate>
                <DataTemplate>
                    <Viewbox Stretch="Fill" >
                        <Grid>
                        <Image Source="{Binding dev_img}" Height="144" Width="128" />
                            <Label Content="{Binding name}" /> 
                        </Grid>
                    </Viewbox>
                </DataTemplate>
            </my:LibraryBar.ItemTemplate>               
        </my:LibraryBar>

到我的文本框:

 <TextBlock HorizontalAlignment="Left" Name="libcontvalue"  VerticalAlignment="Top"  />

我的vb代码:

Dim con As OleDbConnection = New OleDbConnection("Provider=Microsoft.Ace.Oledb.12.0; Data Source=|DataDirectory|\mvdata.accdb")
        con.Open()
        Dim cmd As OleDbCommand = New OleDbCommand("SELECT * FROM devices", con)

        Dim sdr As OleDbDataReader = cmd.ExecuteReader

        libcont.ItemsSource = sdr

1 个答案:

答案 0 :(得分:0)

为什么不将TextBlock.Text绑定到libcont.SelectedItem?

TextBlock Text="{Binding ElementName=libcont,Path=SelectedItem.name,Mode=OneWay,UpdateSourceTrigger=PropertyChanged}"