Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/silverlight/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Silverlight 将UserControl的内容值传输到其内部的控件_Silverlight_Mvvm_Bing Maps - Fatal编程技术网

Silverlight 将UserControl的内容值传输到其内部的控件

Silverlight 将UserControl的内容值传输到其内部的控件,silverlight,mvvm,bing-maps,Silverlight,Mvvm,Bing Maps,我需要扩展bing maps控件,使其对用户MVVM更加友好(具体来说,ZoomLevel和BoundingRect属性不是依赖属性)。我正在将该控件包装在自定义usercontrol中(我还需要添加元素以进行其他地图选择,例如google地图)。我需要将UserControl的内容值传输到BingMapsControl: <UserControl x:Class="RevOptWebControls.MVVMMapControl" xmlns="http://schemas.

我需要扩展bing maps控件,使其对用户MVVM更加友好(具体来说,ZoomLevel和BoundingRect属性不是依赖属性)。我正在将该控件包装在自定义usercontrol中(我还需要添加元素以进行其他地图选择,例如google地图)。我需要将UserControl的内容值传输到BingMapsControl:


<UserControl x:Class="RevOptWebControls.MVVMMapControl" 
    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" 
    mc:Ignorable="d" 
    xmlns:m="clr-namespace:Microsoft.Maps.MapControl;assembly=Microsoft.Maps.MapControl" 
    xmlns:mCore="clr-namespace:Microsoft.Maps.MapControl.Core;assembly=Microsoft.Maps.MapControl"              
    d:DesignHeight="300" d:DesignWidth="400" 
    x:Name="Root"> 

    <Grid x:Name="LayoutRoot" Background="White"> 
        <m:Map CredentialsProvider="Al_H1LepP6chseYMu31RK76El6k4SUkx2KVrxeqobE3rTXooFPieuEJ6qiuA211I" 
               CopyrightVisibility="Collapsed"  
               LogoVisibility="Collapsed" 
               ScaleVisibility="Visible" 
               NavigationVisibility="Visible" 
               x:Name="MyMap"> 
        </m:Map> 
        <ComboBox x:Name="c_MapTypes" HorizontalAlignment="Right" VerticalAlignment="Top" SelectedIndex="0" Height="30" SelectionChanged="MapTypes_SelectionChanged"> 
            <ComboBoxItem>Google Roads</ComboBoxItem> 
            <ComboBoxItem>Google Aerial</ComboBoxItem> 
            <ComboBoxItem>Bing Maps Roads</ComboBoxItem> 
            <ComboBoxItem>Bing Maps Aerial</ComboBoxItem> 
            <ComboBoxItem>Open Street Maps</ComboBoxItem> 
            <ComboBoxItem>Yahoo Street</ComboBoxItem> 
            <ComboBoxItem>Yahoo Aerial</ComboBoxItem> 
            <ComboBoxItem>Blank Map</ComboBoxItem> 
        </ComboBox> 
    </Grid> 
</UserControl>

谷歌道路
谷歌天线
必应地图道路
Bing航空地图
开放式街道地图
雅虎街
雅虎航空
空白地图

更新:想出了怎么做。还共享了控件源代码:

为什么不使用自定义模板尝试
自定义控件。使用

`{TemplateBinding Content}` 
使用
映射
控件绑定
内容

例子:
我知道怎么做了。稍后将发布解决方案。这也会起作用,但我需要模板部分和所有部分来处理更改的选择、映射事件等。实际的解决方案来自于观察MapBase如何从UserControl继承:)关于如何重定向内容属性的博客:好的。学到了新东西!!:)
<Style TargetType="local:MVVMMapControl">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="local:MVVMMapControl">
                <Grid x:Name="LayoutRoot"
                      Background="White">
                    <m:Map CredentialsProvider="Al_H1LepP6chseYMu31RK76El6k4SUkx2KVrxeqobE3rTXooFPieuEJ6qiuA211I"
                           CopyrightVisibility="Collapsed"
                           LogoVisibility="Collapsed"
                           ScaleVisibility="Visible"
                           NavigationVisibility="Visible"
                           x:Name="MyMap"
                           Content="{TemplateBinding ContentControl.Content}"></m:Map>
                    <ComboBox x:Name="c_MapTypes"
                              HorizontalAlignment="Right"
                              VerticalAlignment="Top"
                              SelectedIndex="0"
                              Height="30"
                              SelectionChanged="MapTypes_SelectionChanged">
                        <ComboBoxItem>Google Roads</ComboBoxItem>
                        <ComboBoxItem>Google Aerial</ComboBoxItem>
                        <ComboBoxItem>Bing Maps Roads</ComboBoxItem>
                        <ComboBoxItem>Bing Maps Aerial</ComboBoxItem>
                        <ComboBoxItem>Open Street Maps</ComboBoxItem>
                        <ComboBoxItem>Yahoo Street</ComboBoxItem>
                        <ComboBoxItem>Yahoo Aerial</ComboBoxItem>
                        <ComboBoxItem>Blank Map</ComboBoxItem>
                    </ComboBox>
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>
public class MVVMMapControl : ContentControl // Notice this inherits from ContentControl for its Content Property
{
    public MVVMMapControl()
    {
        this.DefaultStyleKey = typeof(MVVMMapControl);
    }
}