2012-09-08 26 views
0

我有一個佈局如何剪切TextBox寬度以防止出現網格?

<Grid> 
    <Grid.RowDefinitions> 
    <RowDefinition Height="Auto" /> 
    <RowDefinition Height="Auto" /> 
    </Grid.RowDefinitions> 
    <Grid.ColumnDefinitions> 
    <ColumnDefinition Width="60" /> 
    <ColumnDefinition Width="*" /> 
    <ColumnDefinition Width="Auto" /> 
    </Grid.ColumnDefinitions> 

    <Image Grid.Row="0" Grid.RowSpan="2" Grid.Column="0" Width="60" Height="60" /> 

    <StackPanel Grid.Row="0" Grid.Column="1" Grid.ColumnSpan="2" Orientation="Horizontal"> 
    <TextBlock Text="Title should be long" HorizontalAlignment="Left" /> 
    <Ellipse Fill="White" Stroke="White" Width="7" Height="7" /> 
    </StackPanel> 

    <TextBlock Grid.Row="1" Grid.Column="1" Text="Message" /> 
    <TextBlock Grid.Row="1" Grid.Column="2" Text="Info" /> 
</Grid> 

我在那裏舉辦的標題和橢圓StackPanel中有一個問題,我們的目標是通過橢圓whitch應放在最後關閉標題在線標記。但它不應該出於觀點。

我試圖把文本框和橢圓放入網格的單元格不幸它沒有幫助。

<Grid Grid.Row="0" Grid.Column="1" Grid.ColumnSpan="2"> 
    <Grid.ColumnsDefinitions> 
    <ColumnDefinition Width="Auto" /> 
    <ColumnDefinition Width="*" /> 
    </Grid.ColumnsDefinitions> 

    <TextBlock Grid.Column="0" Text="Title should be long" HorizontalAlignment="Left" /> 
    <Ellipse Grid.Column="1" Fill="White" Stroke="White" Width="7" Height="7" /> 

</Grid> 

在我看來,它應該呈現正確的,但橢圓再次出現在視圖端口。

這是一個Expression Blend佈局scrinshots,同樣的佈局是在運行時渲染。

網格範圍:

​​

文本框範圍:

enter image description here

橢圓範圍:

enter image description here

所以特xtBox和橢圓是從柵:(

更新的:我需要佈局

1)簡短標題的下一個行爲,橢圓附着到標題結束

enter image description here

2)長標題,橢圓連接到容器的右側

enter image description here

+0

我不太讓你的要求。橢圓始終位於網格中,因爲它可以延伸以適應網格,如果網格被切割。 –

+0

當頁面大小爲HorisontalAlignment =「Stretch」時,網格不應該更大,但它不會。不管網格寬度是否固定。 –

+0

默認情況下是stetches。無論如何,如果沒有足夠的空間,內容可能會被切斷或溢出。 –

回答

0

我想你代碼,它渲染罰款(換句話說,它在視口渲染。見紅色箭頭)。請查找附上的結果截圖。 (I加入showgridlines只是爲了示出的行和cols)

enter image description here

// ---改變測試和預期效果的固定碼---在XAML //

代碼更改:交換了columndefinitions的寬度值。爲了查看整個文本,將文本添加到文本塊。 (你可以選擇的TextTrimming,而不是取決於你的審美觀。)

<Grid Grid.Row="0" Grid.Column="1" Grid.ColumnSpan="2"> 
    <Grid.ColumnDefinitions> 
     <ColumnDefinition Width="*" /> 
     <ColumnDefinition Width="Auto" /> 
    </Grid.ColumnDefinitions> 

    <TextBlock Grid.Column="0" Text="Title should be really really really really really long" HorizontalAlignment="Left" TextWrapping="Wrap" /> 
    <Ellipse Grid.Column="1" Fill="White" Stroke="White" Width="7" Height="7"/> 
</Grid> 

結果:

enter image description here

+0

請在標題中添加更多單詞 –

+0

我添加了更多文本並對您的代碼進行了更正。看到這個和效果附加到我上面的答案。 –

+0

不允許文字換行:( –