0

我有一个从数据库接收数据的 ObservableCollection 列表,我通过数据绑定将这些数据放入我的网格中。所以,我有一个用户控件,当我单击此网格的一个项目时会出现。我想要我的用户控件的文本框,显示我的网格的选定项目。我已经尝试过使用数据绑定,但文本框没有显示所选项目.. 可能吗?

网格代码:

<FlexGrid:C1FlexGrid 

        x:Name="grid" ItemsSource="{Binding list3, Mode=TwoWay}" 
        AutoGenerateColumns="False" 
        HorizontalAlignment="Left" Height="431" Margin="10,147,0,0" VerticalAlignment="Top" Width="1152" SelectionMode="Row" KeepCurrentVisible="True" Tapped="grid_Tapped" >
        <FlexGrid:C1FlexGrid.DataContext>
            <local:Controller/>
        </FlexGrid:C1FlexGrid.DataContext>

        <FlexGrid:C1FlexGrid.Columns>
            <FlexGrid:Column Binding="{Binding describe}" Header="Describes" Width="800" />
            <FlexGrid:Column Binding="{Binding describeNote}" Header="Describes Notes" Width="300" />
        </FlexGrid:C1FlexGrid.Columns>

    </FlexGrid:C1FlexGrid>

用户控制代码:

<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Binding"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:FlexGrid="using:C1.Xaml.FlexGrid"
x:Class="Binding.popNotas"
mc:Ignorable="d" Height="281.925" Width="656.03">

<Grid>
    <TextBox x:Name="txt2" Text="{Binding SelectedItem.describe, ElementName=grid, Mode=TwoWay}" Height="38" Margin="140,5,141,0" TextWrapping="Wrap" VerticalAlignment="Top">

    </TextBox>

</Grid>

cs代码

public class Controller : Common.BindableBase
{
    //DAOS      
    public TesteDao dao { get; set; }


    private ObservableCollection<ClPasso> _list3 = new ObservableCollection<ClPasso>();
    public ObservableCollection<ClPasso> list3
    {
        get { return _list3; }
        set { this.SetProperty(ref this._list3, value); }
    }


    public Controller()
    {
        OnNavigatedTo();

    }
    protected async void OnNavigatedTo()
    {
        await InitializeDatabase();
        list3 = await createlist3();
    }

    private async Task InitializeDatabase()
    {
        string datbasePath = Windows.Storage.ApplicationData.Current.LocalFolder.Path + "\\bd_example.db";
        DataBase database = new DataBase (datbasePath);
        await database.initialize();
        dao = new TesteDao(database);

    }


    public async Task<ObservableCollection<ClPasso>> createlist3()
    {
        return await dao.joinListAsync(123, "924be4cc-16db-40c2-b342-d6c1fccbec86");
    }

  }

帮助!

谢谢!!!

4

1 回答 1

0

我已经解决了我的问题..

所以,我在我的用户控件后面的代码上创建了一个 DependencyProperty,命名选择,然后我把它放在我的文本框的文本中。之后,当我将使用我的用户控件时,在我的主页中,我将值传递给财产..

像这样:

用户控制

 public sealed partial class UCNotes : UserControl
{


    public string selection
    {
        get { return (string)GetValue(selectionProperty); }
        set { SetValue(selectionProperty, value); }
    }

    public static readonly DependencyProperty selecionadoProperty =
        DependencyProperty.Register("selection", typeof(string), typeof(UCNotes), new PropertyMetadata(null));

用户控制 XAML

<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Test"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:FlexGrid="using:C1.Xaml.FlexGrid"
x:Class="Fiscalizacao.UCNotes"
mc:Ignorable="d"
d:DesignHeight="327.068" Width="799.248">

<Grid Margin="10,0,10,10" Background="#FFB2B2B2" Height="303" VerticalAlignment="Bottom">
    <TextBox x:Name="txtSelection" Text="{Binding selection}" Height="38" Margin="153,75,153,0" TextWrapping="Wrap" VerticalAlignment="Top" BorderBrush="Black"/>

主页 XAML

 <FlexGrid:C1FlexGrid 
            x:Name="questionsGrid" 
            HorizontalAlignment="Left" Height="417" Margin="31,181,0,0" VerticalAlignment="Top" Width="1306" 
            AutoGenerateColumns="False" KeepCurrentVisible="True" 
            SelectionMode="Row" ItemsSource="{Binding list, Mode=TwoWay}">
            <FlexGrid:C1FlexGrid.Columns>
                <FlexGrid:Column Binding="{Binding describes}" Header="Descrição" Width="900" />
                <FlexGrid:Column Binding="{Binding descibesNotes}" Header="Nota" Width="*" />
            </FlexGrid:C1FlexGrid.Columns>
        </FlexGrid:C1FlexGrid>

        <Popup x:Name="popNotes" IsLightDismissEnabled="True" IsOpen="False" HorizontalAlignment="Center" VerticalAlignment="Center" Grid.Row="1" Grid.Column="1" Margin="0,0,700,300" >
            <local:UCNotes selection="{Binding SelectedItem.describes, ElementName=questionsGrid" />

        </Popup>
于 2013-07-18T16:47:07.567 回答