我有一個框架,IsVisible 系結到我的模型視圖中設定為 false 的屬性。當我更改外殼中的彈出視窗時,框架會在外殼彈出視窗關閉時出現。知道為什么會這樣嗎?
// in my model view this is the property
public bool ShowPanel{ get { return _showPanel; } set { _showPanel =
value; OnPropertyChange(); } }
// in my view this is the panel
<Frame IsVisible="{Binding ShowPanel}" BackgroundColor="White" BorderColor="Purple" AbsoluteLayout.LayoutFlags="PositionProportional" WidthRequest="100" HeightRequest="200" AbsoluteLayout.LayoutBounds="0,0,200,250">
<local:ExtendedListView ItemTapped="ExtendedListView_ItemTapped" ItemsSource="{Binding AllItems}" IsVisible="{Binding ShowPanel}" SelectionMode="None" HorizontalScrollBarVisibility="Always" HorizontalOptions="Fill" VerticalOptions="Fill" BackgroundColor="Transparent">
<local:ExtendedListView.ItemTemplate >
<DataTemplate>
<ViewCell>
<Grid Padding="0">
<Grid.RowDefinitions>
<RowDefinition Height="20" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="10*"></ColumnDefinition>
<ColumnDefinition Width="10*"></ColumnDefinition>
<ColumnDefinition Width="20*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Image Grid.Column="0" Image.Source="{Binding ImageUrl}" HorizontalOptions="FillAndExpand" VerticalOptions="CenterAndExpand" WidthRequest="50" HeightRequest="50" x:DataType="local1:ServiceLayers"></Image>
<CheckBox Grid.Column="1" IsChecked="{Binding IsVisible, Mode=TwoWay}" Color="Purple" VerticalOptions="Center" HorizontalOptions="Center" x:DataType="local1:ServiceLayers"></CheckBox>
<Label Padding="-5,0,0,0" HorizontalOptions="StartAndExpand" FontAttributes="Bold" TextColor="Black" Grid.Row="0" Grid.Column="2" HorizontalTextAlignment="Start" Text="{Binding Name}" x:DataType="local1:Service"></Label>
<Label></Label>
</Grid>
</ViewCell>
</DataTemplate>
</local:ExtendedListView.ItemTemplate>
</local:ExtendedListView>
</Frame>
// In the View Class
protected override bool OnBackButtonPressed() {
await Shell.Current.GoToAsync($"//{nameof(MainPage)}");
return true;
}
uj5u.com熱心網友回復:
如果在您離開頁面時 BindingContext 被洗掉/更改,則 Frame 將在系結失效并由系結引擎更新時出現。您有兩個選擇:
不要手動清除頁面中的 BindingContext,因為導航生命周期和 GC 應該自己清理這些資源。
當系結源無法決議(因為您已將 BindingContext 設為空)或系結源已決議但系結屬性為 null 時,使用系結回退來定義行為。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/334656.html
標籤:xml 沙马林 xamarin.forms 安卓系统
