小编Jas*_*Jas的帖子

在DataTemplate中排列ItemsControl项

出于某种原因,在dataTemplate中添加的项目将不会执行我告诉他们要做的事情!

我试图将一些图像水平放置在一个堆叠面板中,但无论我如何尝试,它们只是垂直移动.

这是我的xaml.

<DataTemplate x:Name="View">
  <Border BorderBrush="Red" BorderThickness="4" >
      <StackPanel  Orientation="Horizontal">
             <ItemsControl ItemsSource="{Binding Path=_Collection, Mode=OneWay}" >
                 <ItemsControl.ItemTemplate>
                      <DataTemplate >
                          <Image Source="{Binding _Source}" />
                      </DataTemplate>
                 </ItemsControl.ItemTemplate>
             </ItemsControl>
         <TextBlock Height="30" FontFamily="Trebuchet MS" FontSize="18" Text="{Binding _Name}" />
      </StackPanel>
  </Border>
</DataTemplate>
Run Code Online (Sandbox Code Playgroud)

一切都很好.这是从用户控件内部调用的

<ItemsControl ItemTemplate="{StaticResource siteView}" ItemsSource="{Binding Path=_SiteDisplay"/>
Run Code Online (Sandbox Code Playgroud)

我的obervable集合_SiteDisplay包含另一个名为_Collection的oberservable集合,它保存图像的url.

这是从实际代码中删除的,但说明了问题.我不能让图像水平对齐!非常感谢任何帮助 - 或建议更好的方法.

c# silverlight datatemplate itemscontrol stackpanel

3
推荐指数
1
解决办法
6770
查看次数

MVVM Light - 带有Pushpins的Relaycommand

我是将一些图钉绑定到MapLayer的数据.它们显示正常,但是当我使用relay命令从鼠标leftbuttonUp传递eventargs时,对象源是一个elipse.我在MapPolygon上使用了这个方法,并从对象中获取了我想要的信息.

因为我是mvvm的新手,也许我正在接受这一点,所以请让我知道!

这适用于我的MapPolygons(vm引用我的extendedMapPolygon类的命名空间)

    <DataTemplate x:Name="polyTemplate">
        <vm:extendedMapPolygon cName="{Binding _cName}" Locations="{Binding _Locations}" />
    </DataTemplate>
Run Code Online (Sandbox Code Playgroud)

这是MapLayer中的XAML

    <m:MapItemsControl ItemTemplate="{StaticResource polyTemplate}" ItemsSource="{Binding  Path=_PolyforDisplay, Mode=TwoWay}"  >
        <i:Interaction.Triggers>
               <i:EventTrigger EventName="MouseLeftButtonUp">
                    <cmd:EventToCommand Command="{Binding Path=PolySelCommand}" PassEventArgsToCommand="True" ></cmd:EventToCommand>
               </i:EventTrigger>
        </i:Interaction.Triggers>
    </m:MapItemsControl>
Run Code Online (Sandbox Code Playgroud)

在我的viewModel构造函数中

PolySelCommand = new RelayCommand<MouseButtonEventArgs>(PolySelCommandExecute);
Run Code Online (Sandbox Code Playgroud)

最后是实际的命令

        public RelayCommand<MouseButtonEventArgs> PolySelCommand { get; set; }
    private void PolySelCommandExecute(MouseButtonEventArgs cmp)
    {
        Polygon poly = cmp.OriginalSource as Polygon;
        extendedMapPolygon ePoly = poly.Parent as extendedMapPolygon;
        _MapPolygonSelected =  ePoly.cName;
    }
Run Code Online (Sandbox Code Playgroud)

(我把它放在这里,以显示我目前使用的方法,并希望它可能对其他人有用!)

然而,当我用Pushpin尝试相同的东西时,cmp.OriginalSource是一个椭圆,我似乎无法得到任何其他东西.

我的Pushpin代码(我只是在这段代码中使用MapControl中的Pushpins)

    <DataTemplate x:Name="ppTemplate">
        <m:Pushpin ToolTipService.ToolTip="{Binding _psName}" Location="{Binding _Location}" />
    </DataTemplate>

    <m:MapItemsControl ItemTemplate="{StaticResource ppTemplate}" …
Run Code Online (Sandbox Code Playgroud)

silverlight bing-maps pushpin mvvm-light

2
推荐指数
1
解决办法
2780
查看次数