控件作为Grid的背景
我有一个网格,我需要一个控件作为该网格的背景。该控件将是一个进度条,但如何创建它是我的问题。
我找不到如何将控件设置为网格背景。
您有解决此类问题的经验吗?
<DataTemplate x:Key="TodoItemWeeklyTemplate">
<Grid MinWidth="800" Background="Transparent">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Image Grid.Column="0" HorizontalAlignment="Left" VerticalAlignment="Top" Source="{Binding Occurrence.Appointment.Icon, Converter={StaticResource imgConverter}}" Width="16" Height="16" Stretch="Fill" />
<TextBlock Grid.Column="1" HorizontalAlignment="Left" MaxWidth="130" Text="{Binding Occurrence.Appointment.Subject}" />
</Grid>
</DataTemplate>
I have a grid, and I need to have a control as background of this grid. This control will be a progressbar, but it's my problem how to create it.
I can't find how can I set a control as background of grid.
Have you got any experience with this kind of problem?
<DataTemplate x:Key="TodoItemWeeklyTemplate">
<Grid MinWidth="800" Background="Transparent">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Image Grid.Column="0" HorizontalAlignment="Left" VerticalAlignment="Top" Source="{Binding Occurrence.Appointment.Icon, Converter={StaticResource imgConverter}}" Width="16" Height="16" Stretch="Fill" />
<TextBlock Grid.Column="1" HorizontalAlignment="Left" MaxWidth="130" Text="{Binding Occurrence.Appointment.Subject}" />
</Grid>
</DataTemplate>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
以下是我的做法:-
其中
WidthConv
是添加到实现IValueConverter
的用户控件资源中的类的实例。Convert
方法将获取输入的百分比值并将其应用于参数以返回表示该百分比值的矩形所需的宽度。这里重要的一点是,当
Grid
占据相同区域时,元素自然会相互覆盖。Here is how I would do it:-
Where
WidthConv
is an instance of a class added to the usercontrol resources that implementsIValueConverter
. TheConvert
method would take the input percentage value and apply it to the parameter to return the width the rectangle needs to be to represents that percentage value.The important point here is that
Grid
naturaly overlays elements on each other when the occupy the same area.您无法将控件设置为背景,因为它是
Brush
类型。但如果你想模仿,你可以将你的网格放入另一个网格中,如下所示:
You cannot set a control as a background as it is of
Brush
Type.But if you want to emulate that you can put your Grid in another one like that :