1
我正在使用WPF
聊天控制變量和我設計ListView
爲房間列表WPF得到的ListView
MainWindow.xaml
<ListView x:Name="listView_RoomList" Grid.Row="1" Grid.ColumnSpan="2"
ScrollViewer.HorizontalScrollBarVisibility="Visible" SelectionMode="Single"
Visibility="{Binding ElementName=comboBox_CntList, Path=Items.IsEmpty,
Converter={StaticResource VisibilityConverter}}">
<ListView.View>
<GridView ColumnHeaderTemplate="{Binding Path=Rooms}">
<GridView.Columns>
<GridViewColumn x:Name="gridViewColumn_RoomName" Width="100">
<GridViewColumn.CellTemplate>
<DataTemplate>
<Label Content="{Binding Path=Name}"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn x:Name="gridViewColumn_Master" Width="100">
<GridViewColumn.CellTemplate>
<DataTemplate>
<Label Content="{Binding Path=Master}"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn x:Name="gridViewColumn_MaxConnectorNum">
<GridViewColumn.CellTemplate>
<DataTemplate>
<Label Content="{Binding Path=MaxConnectorNum, Converter={StaticResource MaxConnectorNumConverter}}"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn x:Name="gridViewColumn_IsNeedPassword">
<GridViewColumn.CellTemplate>
<DataTemplate>
<PasswordBox x:Name="passwordBox_PW" MinWidth="100" IsEnabled="{Binding Path=IsNeedPassword}"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn x:Name="gridViewColumn_EntryButton">
<GridViewColumn.CellTemplate>
<DataTemplate>
<Button Background="Aqua" Click="button_Entry_Click">
<StackPanel Orientation="Horizontal">
<Image Height="Auto" Width="Auto" Source="Resources/login.png"/>
<TextBlock Text="{Binding Converter={StaticResource EntryButtonConverter}}" VerticalAlignment="Center"/>
</StackPanel>
<Button.Tag>
<!-- I can get a Room ID!! -->
<Binding Path="ID"/>
</Button.Tag>
</Button>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn x:Name="gridViewColumn_DeleteButton">
<GridViewColumn.CellTemplate>
<DataTemplate>
<Button Background="Orange" Click="button_Delete_Click" IsEnabled="{Binding Path=Master, Converter={StaticResource DeleteButtonVisibilityConverter}}">
<StackPanel Orientation="Horizontal">
<Image Height="Auto" Width="Auto" Source="Resources/login.png"/>
<TextBlock Text="{Binding Converter={StaticResource DeleteButtonConverter}}" VerticalAlignment="Center"/>
</StackPanel>
</Button>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView.Columns>
</GridView>
</ListView.View>
</ListView>
一個GridView Row
有Room
類。
Room.cs
public class Room
{
public uint ID { get; private set; }
public string Name { get; private set; }
public string Master { get; internal set; }
public short MaxConnectorNum { get; private set; }
public bool IsNeedPassword { get; private set; }
}
每個房間都有一個ID
因此,當叫button_Entry_Click
功能,我可以得到一個房間ID。
MainWindow.xaml.cs
private void button_Entry_Click(object sender, RoutedEventArgs e)
{
Button b = (Button)sender;
MessageBox.Show(b.Tag);
}
這樣的事情。
我能得到的只是Button
但是,我想PasswordBox
輸入密碼等..
因爲我想找到方法,這是從房間ID獲得所有的行控制。
我該如何編碼?
在此先感謝。
哇..你是WPF的專家?非常感謝! – Lee 2014-09-13 18:59:36