2013-10-19 21 views
0

如何讓我的中間一列佔用全部可用寬度,同時允許註釋部分空間,使所有這些評論框是很好的右對齊:XAML中,中間一列不佔用全寬

enter image description here

<DataTemplate x:Key="ActivityStreamItemTemplate"> 
     <StackPanel VerticalAlignment="Top" Margin="5,0,0,0"> 
      <Button Command="{Binding Path=DataContext.LoadSpacesCommand, ElementName=OrganisationList}" CommandParameter="{Binding}" Padding="-5,0,-5,-5" Margin="-7,-12,-7,-7" Height="auto" BorderThickness="0" HorizontalAlignment="Left" VerticalAlignment="Stretch" HorizontalContentAlignment="Left" UseLayoutRounding="True" FontSize="0.01"> 
       <Grid Height="auto"> 
        <Grid.ColumnDefinitions> 
         <ColumnDefinition Width="67" /> 
         <ColumnDefinition Width="*"/> 
         <ColumnDefinition Width="60" /> 
        </Grid.ColumnDefinitions> 
        <StackPanel Height="auto" Grid.Column="0" Background="Transparent"> 
         <Border Background="Transparent" BorderThickness="0" Width="62" Height="62" HorizontalAlignment="Left" Margin="0,0,0,5"> 
          <Image Source="{Binding created_by.image.link}" Width="62" Height="62"></Image> 
         </Border> 
        </StackPanel> 
        <StackPanel Height="auto" Grid.Column="1"> 
         <TextBlock Text="{Binding type}" HorizontalAlignment="Left" FontSize="30" VerticalAlignment="Center" Margin="0,0,0,5" Foreground="White" /> 
         <TextBlock Text="{Binding ttitle}" HorizontalAlignment="Left" FontSize="15" VerticalAlignment="Center" Margin="0,0,0,5" Foreground="White" TextWrapping="Wrap"/> 
         <TextBlock Text="{Binding created_by.name}" HorizontalAlignment="Left" FontSize="11" VerticalAlignment="Center" Margin="0,0,0,5" Foreground="White" /> 
        </StackPanel> 
        <StackPanel Height="60" Grid.Column="2" Margin="10,0,0,0"> 
         <StackPanel.Background> 
          <ImageBrush Stretch="Fill" ImageSource="/Assets/Icons/CommentsIcon.png"/> 
         </StackPanel.Background> 
         <TextBlock Text="{Binding comments.Count}" HorizontalAlignment="Center" FontSize="20" Foreground="Black" TextAlignment="Center" Padding="0,8,0,0"/> 
        </StackPanel> 
       </Grid> 
      </Button> 
     </StackPanel> 
    </DataTemplate> 

我試着在第三個stackpanel上放置水平對齊,但實際上並沒有工作。

編輯:謝謝你的嘗試,但沒有雪茄:

enter image description here

+0

可能重複(http://stackoverflow.com/questions/14539961/right-align-content-in-listbox) –

+0

這是一個常見的問題,相當令人沮喪,你必須解決一些應該默認的東西。 http://stackoverflow.com/questions/14539961/right-align-content-in-listbox/14543768#14543768 –

+0

詹姆斯,你看看我的評論中的鏈接?這是你的解決方案 –

回答

0

玩弄的列給出的空間,例如:

   <Grid.ColumnDefinitions> 
        <ColumnDefinition Width="67" /> 
        <ColumnDefinition Width="3*"/> 
        <ColumnDefinition Width="1*" /> 
       </Grid.ColumnDefinitions> 

這使中心柱3次比右列更多的空間

+0

這個改變是如何發生的?我認爲所有親屬都是因爲*? – Jimmyt1988

+0

是的,第67個是WPF'像素'(最好是1/96英寸)。另外兩個是相對寬度,這將根據可用空間而變化 – Dweeberly

+0

感謝您的嘗試,我明確地使用了您的嘗試,並嘗試將最後一個寬度設置爲60(因爲我的消息框實際上應該是60)...不幸的是,它並沒有真正的工作..雖然它確實推動了他們多一點..如果有的話,它會更好。所以謝謝你的嘗試!因此OP可用於新視覺 – Jimmyt1988

0

很難準確地告訴你想要什麼,因爲你對圖像的模糊程度。但我認爲關鍵是要讓電網的容器佔用所有可用空間,HorizontalAlignment="Stretch"

<DataTemplate> 
    <StackPanel HorizontalAlignment="Stretch"> 
     <Grid> 
      <Grid.ColumnDefinitions> 
       <ColumnDefinition Width="67" /> 
       <ColumnDefinition Width="*"/> 
       <ColumnDefinition Width="60" /> 
      </Grid.ColumnDefinitions> 

      <!-- items here --> 
     </Grid> 
</StackPanel> 

設置有Grid.Column="0"將有寬度67dip該項目時,一個與Grid.Column="2"將寬度60dip,和一個與Grid.Column="1"將填補空間的其餘部分。

dip =與設備無關的像素 - 測量所有Windows Phone應用程序,就好像屏幕是480x800,然後以實際的屏幕分辨率渲染。

2

您需要更改ListBoxItem本身的樣式,以確保內容在可用寬度範圍內伸展。

定義這種風格:

<Style x:Key="ListBoxItemStyle" TargetType="ListBoxItem"> 
    <Setter Property="HorizontalContentAlignment" Value="Stretch" /> 
    <Setter Property="HorizontalAlignment" Value="Stretch" /> 
</Style> 

那麼「意見」的形象右對齊將工作和中央文本框將拉伸以填充可用空間。

您可能會發現,對於項目模板,使用水平方向的StackPanel的效果要好於Grid,尤其是在列0和2的數據寬度恆定的情況下。

+0

謝謝克里斯,當我回家的時候,我會放棄這一切。接下來的名單(原諒雙關語)永遠不會結束名單 - 虛擬化(顯然是所謂的):)感謝您的辛勤工作! – Jimmyt1988

0

在StackPanel中,您不能對Horizo​​ntalLeignment進行右對齊,而其方向爲LeftToRight,據我所知。避免使用它。

0

你的問題是按鈕,如果它不是強制性的嘗試刪除它,並添加一個「點擊「事件StackPanel,我已經嘗試過,它的工作原理。

<DataTemplate x:Key="ActivityStreamItemTemplate"> 

    <StackPanel Tap="..."> 
     // no <Button> here 
      <Grid> 
       --- 
      </Grid> 
     // no </Button> here 
    </StackPanel> 

</DataTemplate> 

更好的選擇

<DataTemplate x:Key="ActivityStreamItemTemplate"> 

    <Grid Tap="..."> 
     ... 
    </Grid> 

</DataTemplate> 
的[右對齊列表框內容]
+0

你還可以將命令綁定到這個嗎? (我會嘗試,但我目前在工作,沒有在這裏)Tap =綁定MyCommand – Jimmyt1988