2012-03-27 180 views
0

除了一件事之外,我已經成功轉換了幾乎所有的東西。將WPF xaml轉換爲Silverlight xaml

這是有問題的部分 -

<ContentPresenter Margin="2,2,2,2" x:Name="PART_SelectedContentHost" ContentSource="SelectedContent"/> 

這是整個XAML(沒有那麼長) -

<Window.Resources> 
    <SolidColorBrush x:Key="OutlookButtonForeground" Color="#FF204D89"/> 

    <LinearGradientBrush x:Key="OutlookButtonBackground" EndPoint="0.5,1" StartPoint="0.5,0"> 
     <GradientStop Color="#FFD9EDFF" Offset="0"/> 
     <GradientStop Color="#FFC0DEFF" Offset="0.445"/> 
     <GradientStop Color="#FFC0D9FB" Offset="1"/> 
     <GradientStop Color="#FFAFD1F8" Offset="0.53"/> 
    </LinearGradientBrush> 

    <LinearGradientBrush x:Key="OutlookButtonHighlight" EndPoint="0.5,1" StartPoint="0.5,0"> 
     <GradientStop Color="#FFFFBD69" Offset="0"/> 
     <GradientStop Color="#FFFFB75A" Offset="0.0967"/> 
     <GradientStop Color="#FFFFB14C" Offset="0.2580"/> 
     <GradientStop Color="#FFFB8C3C" Offset="0.3870"/> 
     <GradientStop Color="#FFFEB461" Offset="0.9677"/> 
     <GradientStop Color="#FFFEBB67" Offset="1"/> 
    </LinearGradientBrush> 

    <Style x:Key="OutlookTabControlStyle" TargetType="TabControl"> 
     <Setter Property="Foreground" Value="{StaticResource OutlookButtonForeground}"/> 
     <Setter Property="Background" Value="{StaticResource OutlookButtonBackground}"/> 

     <Setter Property="BorderThickness" Value="3"/> 
     <Setter Property="Margin" Value="0"/> 
     <Setter Property="Padding" Value="1"/> 
     <Setter Property="MinWidth" Value="10"/> 
     <Setter Property="MinHeight" Value="10"/> 
     <Setter Property="HorizontalContentAlignment" Value="Center"/> 
     <Setter Property="VerticalContentAlignment" Value="Center"/> 
     <Setter Property="Template"> 
      <Setter.Value> 
       <ControlTemplate TargetType="TabControl"> 
        <Grid> 
         <Grid.RowDefinitions> 
          <RowDefinition x:Name="RowDefinition0" Height="Auto"/> 
          <RowDefinition x:Name="RowDefinition1" Height="*"/> 
         </Grid.RowDefinitions> 
         <Grid.ColumnDefinitions> 
          <ColumnDefinition x:Name="ColumnDefinition0"/> 
          <ColumnDefinition x:Name="ColumnDefinition1" Width="0"/> 
         </Grid.ColumnDefinitions> 
         <Grid x:Name="ContentPanel" Grid.Column="0" Grid.Row="1"> 
          <Border 
        Background="{TemplateBinding Background}" 
        BorderBrush="{TemplateBinding BorderBrush}" 

        BorderThickness="{TemplateBinding BorderThickness}"> 
           <ContentPresenter Margin="2,2,2,2" x:Name="PART_SelectedContentHost" ContentSource="SelectedContent"/> 
          </Border> 
         </Grid> 
         <StackPanel HorizontalAlignment="Stretch" Margin="0,-2,0,0" 
       x:Name="HeaderPanel" VerticalAlignment="Bottom" Width="Auto" 
      Height="Auto" Grid.Row="1" IsItemsHost="True"/> 
        </Grid> 
       </ControlTemplate> 
      </Setter.Value> 
     </Setter> 
    </Style> 
</Window.Resources> 
<Grid> 
    <TabControl VerticalAlignment="Stretch" Width="360" Height="Auto" TabStripPlacement="Bottom" Style="{StaticResource OutlookTabControlStyle}" BorderBrush="#FF6593CF" HorizontalAlignment="Left" BorderThickness="1,1,1,0"> 
     <TabItem Header="Mail" Height="30" Background="{StaticResource OutlookButtonBackground}" Foreground="{StaticResource OutlookButtonForeground}"> 
      <Grid> 
       <TextBlock Text="Mail"/> 
      </Grid> 
     </TabItem> 
     <TabItem Header="Calender" Height="30" Background="{StaticResource OutlookButtonBackground}" Foreground="{StaticResource OutlookButtonForeground}"> 
      <Grid> 
       <TextBlock Text="Calender"/> 
      </Grid> 
     </TabItem> 
    </TabControl> 
</Grid> 

回答

0

ContentSource沒有爲Silverlight中ContentPresenter控制依賴項屬性。不幸的是,我不知道Silverlight中的use/equivilant屬性,因此我會查看msdn文檔以瞭解如何遷移該值(http://msdn.microsoft.com/zh-cn/library/system。 windows.controls.contentpresenter(v = vs.95).aspx)

+0

感謝@Dave S,那麼我應該在那裏寫什麼呢? – Erez 2012-03-27 13:48:04

+0

我不確定什麼是SelectedContent值被設置? - 猜測它只是看起來像內容,所以嘗試使用內容DP來代替。 – 2012-03-27 13:48:56