私CommandBar
の IsOpen プロパティは XAML で true に設定されているため、説明を表示したままにしたいので、各ボタンのテキストが表示されます。
省略記号ボタンをクリックすると、テキストが非表示になり、2 回目にクリックすると、次のエラーが表示されます。
No installed components were detected. Cannot resolve TargetName HighContrastBorder
.
UI で何かおかしなことが起こっており、これに関連している可能性がありますが、何が原因なのかわかりません:
ご覧のとおり、ボタンのテキストは、表示しているさまざまなボタンで途切れています。
コードに関しては、私が見る限り、特別なことは何もありません:
<Page.BottomAppBar>
<CommandBar IsOpen="True"
ClosedDisplayMode="Compact"
IsSticky="True"
Visibility="{Binding
CommandBarViewModel.IsCommandBarVisible,
Converter={StaticResource BoolToVisibilityConverter}}"
Background="{ThemeResource SystemControlBackgroundAccentBrush}">
<AppBarButton
Icon="Add"
Label="Add"
Foreground="White"
Command="{Binding CommandBarViewModel.AddCommand}"
Visibility="{Binding CommandBarViewModel.IsAddVisible,
Converter={StaticResource BoolToVisibilityConverter}}"/>
<AppBarButton
Icon="Refresh"
Label="Refresh"
Foreground="White"
Command="{Binding CommandBarViewModel.RefreshListCommand}"
Visibility="{Binding
CommandBarViewModel.IsRefreshListVisible,
Converter={StaticResource BoolToVisibilityConverter}}"/>
</CommandBar>
</Page.BottomAppBar>
InnerException はなく、例外は App.gics からスローされます
#if DEBUG && !DISABLE_XAML_GENERATED_BREAK_ON_UNHANDLED_EXCEPTION
UnhandledException += (sender, e) =>
{
if (global::System.Diagnostics.Debugger.IsAttached)
global::System.Diagnostics.Debugger.Break();
};
#endif
私の問題、つまりテキストの切り取りと未処理の例外の両方に関するアイデアはありますか?
ありがとう
更新 - 1:
のプロパティCommandBarViewModel.IsCommandBarVisible
からバインドされたプロパティ ( )を削除し、それを にハードコーディングすると、エラーが下に移動し、App.gics で発生する代わりに、設定しようとしている最初のボタンのバインドされたプロパティが発生するようになりました。 IE での可視性Visible
CommandBar
Visible
<AppBarButton
Icon="Add"
Label="Add"
Foreground="White"
Command="{Binding CommandBarViewModel.AddCommand}"
Visibility="{Binding CommandBarViewModel.IsAddVisible,
Converter={StaticResource BoolToVisibilityConverter}}"/>
しかし、今回は次のエラーが発生します。
An exception of type 'System.Runtime.InteropServices.COMException'
occurred in GalaSoft.MvvmLight.dll but was not handled in user code
WinRT information: Cannot resolve TargetName HighContrastBorder.
Additional information: No installed components were detected.
ご覧のとおり似ていますが、MVVMLight から来ているようです??? 意味がありません!
これを解決する方法に関する提案/アイデアはありますか?
更新 - 2:
すべての可視性プロパティ (および対応するバインディング) を削除すると、それに応じてコマンドが表示され (つまり、カットオフ テキストがなくなります)、省略記号ボタンを何度もクリックしてもクラッシュしなくなります!!
したがって、それは間違いなく可視性に関連しており、それをビューモデルのプロパティにバインドしていますが、正確にはわかりません。
ViewModel はページが読み込まれたときにのみ構築され、この段階では CommandBar とそのボタンを正しく初期化するには遅すぎます。
ボタンの表示/非表示に関するすべてが期待どおりに機能するのは奇妙ですが、テキストが途切れて省略記号ボタンをクリックできないか、クラッシュします。
更新 - 3:
私は回避策を見つけましたが、それが間違っていると感じているので、それについて飛び跳ねたりはしませんが、今のところはそうします。このエラーを回避するために、ViewModel を初期化するときにコマンド バーとボタンを表示するように設定し、それが表示されているページに応じて非表示にします。
public class AppShellViewModel { public void AppShellViewModel { this.CommandBarViewModel.IsCommandBarVisible = true; this.CommandBarViewModel.IsAddVisible = true; this.CommandBarViewModel.IsRefreshVisible = true; this.CommandBarViewModel.IsCancelVisible = true; }
...
\\Hide buttons accordingly in the various parts of your app.
this.CommandBarViewModel.IsCancelVisible = false;
}
個人的には、最初からそれ (およびそのボタン) を非表示にできるはずなので、CommandBar コントロールとボタンのバグのように感じます。
a)エラーなしでこれを処理できる。b) テキストが途切れることなく、自分自身を正しく「再描画」できること。
もちろん、私は間違っている可能性があり、それは私のコードに関係している可能性がありますが、私の観点からは、可視性バインディングを削除して修正し、最初に可視化すると修正されるため、このように下向きになっているようです。
更新 - 4:
これが実際のコードです。CommandBar とそのボタンだけを残して、できる限り単純化しました (つまり、名前空間、DataTemplates、メイン コンテンツなどを削除しました)。うまくいけば、これは役に立ちます。
mvvmlight を使用するとわかるように、ソースは に設定されLocator
、パスは関連するViewModel
に設定されます。この例では、AppShellViewModel です。
しかし、グレースに説明したように、バインドの代わりに x:bind を使用すると、次のエラーが発生します。
Invalid binding path 'CommandBarViewModel.IsCommandBarVisible' :
Property 'CommandBarViewModel' can't be found on type 'AppShell'
MyApp ..\MyApp\Views\AppShell.xaml
XAML コード:
<Page.Resources>
<converters:NullToVisibilityConverter x:Key="NullToVisibilityConverter" />
<converters:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter" />
<x:Double x:Key="EllipseDimension">30</x:Double>
</Page.Resources>
<Page.BottomAppBar>
<CommandBar x:Name="AppBar"
IsOpen="{x:Bind CommandBarViewModel.IsCommandBarVisible}"
ClosedDisplayMode="Compact"
IsSticky="{x:Bind CommandBarViewModel.IsCommandBarVisible}"
Visibility="{x:Bind CommandBarViewModel.IsCommandBarVisible,
Converter={StaticResource BoolToVisibilityConverter}}"
Background="{ThemeResource SystemControlBackgroundAccentBrush}"
IsEnabled="{x:Bind IsNotBusy}">
<AppBarButton
Icon="Add"
Label="Add"
Foreground="White"
Command="{x:Bind CommandBarViewModel.RegisterCommand}"
Visibility="{x:Bind CommandBarViewModel.IsRegisterVisible,
Converter={StaticResource BoolToVisibilityConverter}}"/>
<AppBarButton
Icon="Refresh"
Label="Refresh"
Foreground="White"
Command="{x:Bind CommandBarViewModel.RefreshListCommand}"
Visibility="{x:Bind CommandBarViewModel.IsRefreshListVisible,
Converter={StaticResource BoolToVisibilityConverter}}"/>
</CommandBar>
</Page.BottomAppBar>
</Page>
ありがとう。