WPF移动文本“;“外部”;其自身元素的边界
我正在用ItemsControl创建一个LinearGauge控件。我想显示的边界标签正好在两个酒吧的中心。我将尝试在下面的屏幕截图中描述我的问题: 因此,标签都应该向右移动几个像素。但问题当然是,元素边界是下一个彩色条开始的地方。所以我想移动标签“同时忽略元素边界” 做那样的事有什么简单的诀窍吗 到目前为止,我拥有的xaml:WPF移动文本“;“外部”;其自身元素的边界,wpf,xaml,Wpf,Xaml,我正在用ItemsControl创建一个LinearGauge控件。我想显示的边界标签正好在两个酒吧的中心。我将尝试在下面的屏幕截图中描述我的问题: 因此,标签都应该向右移动几个像素。但问题当然是,元素边界是下一个彩色条开始的地方。所以我想移动标签“同时忽略元素边界” 做那样的事有什么简单的诀窍吗 到目前为止,我拥有的xaml: <ItemsControl Grid.Row="0" Grid.Column="0" ItemsSou
<ItemsControl
Grid.Row="0"
Grid.Column="0"
ItemsSource="{Binding Elements}">
<ItemsControl.Resources>
<DataTemplate DataType="{x:Type local:HorizontalGaugeElement}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Rectangle
Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="3"
Height="30"
Fill="{Binding Color}">
<Rectangle.Width>
<MultiBinding Converter="{StaticResource BoundsToWidthConverter}">
<Binding Path="Lower"/>
<Binding Path="Upper"/>
<Binding RelativeSource="{RelativeSource AncestorType={x:Type ItemsControl}}" Path="DataContext.ValueToPercentage"/>
<Binding RelativeSource="{RelativeSource AncestorType={x:Type ItemsControl}}" Path="DataContext.GaugeSize"/>
</MultiBinding>
</Rectangle.Width>
</Rectangle>
<TextBlock
Visibility="{Binding ShowLowerBoundary, Converter={StaticResource BooleanToVisibilityConverter}}"
Grid.Row="1" Grid.Column="0"
Text="{Binding Lower}"
Margin="5, 0, 0, 0">
</TextBlock>
<TextBlock
Grid.Row="1" Grid.Column="2"
Text="{Binding Upper}" TextAlignment="Right"
Margin="0, 0, 0, 0">
</TextBlock>
</Grid>
</DataTemplate>
<DataTemplate DataType="{x:Type local:VerticalGaugeElement}">
<!-- similar story but then vertical -->
</DataTemplate>
</ItemsControl.Resources>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="{Binding IsHorizontal, Converter={StaticResource BoolToOrientationConverter}}"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
尝试负边距:margin=“0,0,-5,0”
或rendertransform translatetransform。具有正X值。像一个符咒,thx@ash像一个符咒,thx@Andy:)。两者都很完美