2016-03-03 23 views
0

我有一堆兒童在其中的相對面板。我想通過VisualStates中的AdoptiveTrigger來改變兒童的位置。 問題是,當我想要從其他元素的下方更改元素位置到該元素的右側時,我必須刪除Below Attached Property的值,然後設置RightOf屬性以使其工作,否則會使應用程序崩潰。 現在我想現在如何刪除下面的值? 我試圖 a.reset在每個狀態的屬性窗口中的綁定,然後分配我的值 b.setting該值爲空字符串,如「」; c。忽略該屬性。 這些都沒有工作! 請幫幫我!通過VisualStates在RelativePanel中重新定位兒童

回答

0

你可以做

<Setter Target="SomeElement.(RelativePanel.Below)" Value="{x:Null}" /> 
+0

這給了我這個消息:災難性故障(Exeption fromHRESULT 0x8000FFFF(E_UNEXPECTED)) –

2

設置附加屬性RelativePanel.Below空可以工作。除此之外,我們還可以通過設置AlignTopWithAlignVerticalCenterWith屬性來解決此問題。

這是可行的,因爲AlignTopWith的優先級高於Below,對於AlignVerticalCenterWith屬性,如果沒有衝突,則應用該屬性。作爲我的測試,AlignVerticalCenterWith的優先級也高於Below

欲瞭解更多信息,請參閱RelativePanel類中的Conflicting relationships部分。

以下是我用來測試的樣品:

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> 
    <VisualStateManager.VisualStateGroups> 
     <VisualStateGroup> 
      <VisualState> 
       <VisualState.StateTriggers> 
        <AdaptiveTrigger MinWindowWidth="600" /> 
       </VisualState.StateTriggers> 
       <VisualState.Setters> 
        <Setter Target="BlueRect.(RelativePanel.Below)" Value="" /> 
        <Setter Target="GreenRect.(RelativePanel.RightOf)" Value="BlueRect" /> 
        <Setter Target="GreenRect.(RelativePanel.Below)" Value="RedRect" /> 
        <!--<Setter Target="GreenRect.(RelativePanel.AlignVerticalCenterWith)" Value="BlueRect" />--> 
        <!--<Setter Target="GreenRect.(RelativePanel.AlignTopWith)" Value="BlueRect" />--> 
       </VisualState.Setters> 
      </VisualState> 
     </VisualStateGroup> 
    </VisualStateManager.VisualStateGroups> 

    <RelativePanel> 
     <Rectangle x:Name="RedRect" 
        Width="100" 
        Height="100" 
        Fill="Red" /> 
     <Rectangle x:Name="BlueRect" 
        Width="100" 
        Height="200" 
        Fill="Blue" 
        RelativePanel.Below="RedRect" 
        RelativePanel.RightOf="RedRect" /> 
     <Rectangle x:Name="GreenRect" 
        Width="100" 
        Height="100" 
        Fill="Green" 
        RelativePanel.Below="BlueRect" 
        RelativePanel.RightOf="RedRect" /> 
    </RelativePanel> 
</Grid> 

它是這樣工作: enter image description here

+0

TNX,似乎它的工作原理,我會檢查它,但現在我已經提交了我的應用程序存儲幾個小時前:( –