我正在为传输torrent服务器编写GUI。为了保存我的torrent信息,我使用ObservableCollection:
public partial class Torrents
{
private static ObservableCollection<Torrent> _list = new ObservableCollection<Torrent>();
public static ObservableCollection<Torrent> List { get { return _list; } }
}
为了显示种子我使用绑定到我的ObservableCollection的DataGrid:
<DataGrid x:Name="dataGrid" CanUserReorderColumns="True" AutoGenerateColumns="False" ItemsSource="{Binding Source={StaticResource TorrentsClass}, Path=List}" CanUserResizeRows="False" CanUserSortColumns="True" IsReadOnly="True" CellStyle="{StaticResource RightAlignment}">
<DataGrid.Columns>
<DataGridTextColumn Header="#" Binding="{Binding Path=Id}" />
<DataGridTextColumn Header="Name" Binding="{Binding Path=Name}" />
<DataGridTextColumn Header="Size" Binding="{Binding Path=Size, Converter={StaticResource SizeConverter}}"/>
<DataGridTextColumn Header="Download Speed" Binding="{Binding Path=DownSpeed, Converter={StaticResource SpeedConverter}}"/>
<DataGridTextColumn Header="Upload Speed" Binding="{Binding Path=UpSpeed, Converter={StaticResource SpeedConverter}}"/>
<DataGridTextColumn Header="Ratio" Binding="{Binding Path=Ratio, StringFormat=F2}"/>
</DataGrid.Columns>
</DataGrid>
到目前为止一切正常(无法发布图片):
但是为了显示种子状态(无论是暂停,下载,播种,重新检查还是在所说的内容上取得进展),我想要像uTorrent一样有进度条:
我已经使用ProgressBar和TextBlock创建了一个自定义UserControl,它可以正常工作。
但是如何将UserControl添加到Status列?以及如何将我的ObservableCollection中的数据绑定到它?我想因为它将提供多个数据(进度,具有torrent状态的枚举),是否可以将它绑定到具有所述属性的对象?
稍后我将在DataGrid中实现上下文菜单以允许暂停选定的种子(不知道如何......)等等,也许使用DataGrid不是最好的主意?如果没有,你会建议什么?
答案 0 :(得分:2)
答案 1 :(得分:2)
注意:我假设您使用的是内置的.NET 4.0 DataGrid
。
您需要使用DataGridTemplateColumn
。提前采样:
<DataGrid ...>
<DataGrid.Columns>
<DataGridTemplateColumn>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<my:MyProgressBar Progress="{Binding Progress}" Text="{Binding Status}" ...>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
我猜测了你的房产名称。