2012-11-01 31 views
0

之間沒有空格我定義了一些用戶控件的列表框網格 - 列

<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0"> 
      <ListBox Height="Auto" HorizontalAlignment="Stretch" Name="deliveriesListBox" VerticalAlignment="Stretch" Width="Auto" DataContext="{Binding}" SelectionChanged="deliveriesListBox_SelectionChanged"> 
       <ListBox.ItemTemplate> 
        <DataTemplate> 
         <Grid x:Name="LayoutRoot" xmlns:src="clr-namespace:App" Margin="0,5"> 
          <src:DItem /> 
         </Grid> 
        </DataTemplate>  
       </ListBox.ItemTemplate>      
      </ListBox> 
     </Grid> 

用戶控件是

<UserControl x:Class="App.DItem" 
    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" 
    FontFamily="{StaticResource PhoneFontFamilyNormal}" 
    FontSize="{StaticResource PhoneFontSizeNormal}" 
    Foreground="{StaticResource PhoneForegroundBrush}" 
    d:DesignHeight="480" d:DesignWidth="480"> 

    <Grid x:Name="LayoutRoot" Margin="0,5"> 
     <Grid.RowDefinitions> 
      <RowDefinition Height="Auto" /> 
      <RowDefinition Height="Auto" /> 
     </Grid.RowDefinitions> 
     <Grid.ColumnDefinitions> 
      <ColumnDefinition Width="*"/> 
      <ColumnDefinition Width="Auto"/> 
     </Grid.ColumnDefinitions> 

     <TextBlock Grid.Row="0" Grid.Column="0" FontSize="42" HorizontalAlignment="Left" Text="Hello" VerticalAlignment="Stretch" Margin="0" /> 
     <TextBlock Grid.Row="1" Grid.Column="1" FontSize="20" HorizontalAlignment="Right" TextAlignment="Right" Margin="0"> 
             <Run Text="OK" /> 

     </TextBlock> 
     <TextBlock Grid.Row="1" Grid.Column="0" FontSize="20" Text="this is working only here.." HorizontalAlignment="Left" /> 
    </Grid> 
</UserControl> 

「所見即所得」在VS2010或Expression Blend的4編輯器顯示我「之間,這是唯一的工作空間這裏「和」確定「。這裏圖片 - http://xrep.eu/pic.jpg

和多數民衆贊成什麼,我想,但。在仿真器和手機看起來像http://xrep.eu/emu.jpg

所以,之間「這是工作只有在這裏」和「OK」,沒有空間。 有人可以幫助並告訴我如何定義,「OK」字符串最多在右側嗎?

回答

0

試試這個

<Grid x:Name="LayoutRoot" Grid.Row="1" Margin="0,5"> 
     <Grid.RowDefinitions> 
      <RowDefinition Height="Auto" /> 
      <RowDefinition Height="Auto" /> 
     </Grid.RowDefinitions> 

     <TextBlock Grid.Row="0" FontSize="42" HorizontalAlignment="Left" Text="Hello" VerticalAlignment="Stretch" Margin="0" /> 

     <DockPanel Grid.Row="1"> 
     <TextBlock FontSize="20" HorizontalAlignment="Right" TextAlignment="Right" Margin="0" DockPanel.Dock="Right"> 
            <Run Text="OK" /> 

     </TextBlock> 
     <TextBlock Grid.Row="1" Grid.Column="0" FontSize="20" Text="this is working only here.." HorizontalAlignment="Left" /> 
     </DockPanel> 
    </Grid> 

乾杯

+0

好吧,thx但DockPanel不是Silverlight的一部分 – xrep

0

問題是父控件的寬度。

在設計模式下面的代碼(在該用戶控件的定義)正被執行時:

mc:Ignorable="d" 
d:DesignHeight="480" d:DesignWidth="480" 

這個指定的高度,並且更重要的是,所述控制的寬度。這足夠寬,所以你可以看到兩段文字之間的空間。

在運行時,這被忽略,因此Grid(和UserControl)將顯示正在顯示的項目的寬度。

您有兩種選擇。

  1. 使用MarginPadding屬性放入一些明確的間距。
  2. GridHorizontalAlignment設置爲Stretch

您可能需要做一些實驗和調整才能獲得您想要的效果。