2012-05-10 63 views
1

我在用于执行查询的Web部件内有一个用户控件。用户控件的高度可以增长到某个点,具体取决于有多少结果。 这可能会导致用户控件的标题被推送到可查看区域之外。Silverlight用户控制位置

我想获得用户控件的位置,并且当Y坐标为负时,移动用户控件以使Y坐标为正值。

我使用的代码从这个帖子得到了用户控件的位置: Determine a UIElement's position

但现在,我有我无法弄清楚如何移动用户控件的位置。 我试过使用userControl.SetValue(Canvas.TopProperty, 15.0) 但它没有效果。

是否有另一种方法可以做到这一点?

感谢您的帮助!

编辑:XAML提取被添加

<UserControl x:Class="Gazetteer.Search" 
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
xmlns:sys="clr-namespace:System;assembly=mscorlib" 
xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk" 
mc:Ignorable="d" 
d:DesignHeight="336" d:DesignWidth="342" BorderBrush="{x:Null}"> 

<Grid x:Name="LayoutRoot" Background="#FFE2E2E2" MinHeight="80" MinWidth="280"> 

    <StackPanel Margin="10"> 
     <StackPanel Margin="10" Orientation="Horizontal"> 
      <RadioButton x:Name="townlandRB" Margin="5" Checked="radioBtnCheck" 
      GroupName="Search Type" Content="Townland" /> 
      <RadioButton x:Name="sitecodeRB" Margin="5" Checked="radioBtnCheck" 
      GroupName="Search Type" Content="Site Code" /> 
     </StackPanel>    
    </StackPanel> 

</Grid> 

+1

你能展示你的XAML吗?定位取决于您的用户控件所在的容器类型。否则,你可以使用TranslateTranform来移动它。 –

+0

感谢HiTech MAgic,我使用了TranslateTransform,它现在正在正常工作! – Anto

+0

有用的,但我的意思是包含您的用户控件的页面的Xaml :) –

回答

1

定位依赖于容器上键入您的用户控件中。 Canvas.TopProperty什么都不做,除非父母实际上是一个Canvas。

使用TranslateTransform来移动对象。