5

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 での可視性VisibleCommandBarVisible

        <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>

ありがとう。

4

2 に答える 2

1

あなたのコードでサンプル プロジェクトを作成します。

xaml:

<Page
    x:Class="CommandBarSample.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:CommandBarSample"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" x:Name="root">

    </Grid>

    <Page.BottomAppBar>

            <CommandBar IsOpen="True" 
                IsSticky="True"
                        ClosedDisplayMode="Compact"
                Background="{ThemeResource SystemControlBackgroundAccentBrush}">

                <AppBarButton 
            Icon="Add" 
            Label="Add" 
            Foreground="White"
            Command="{Binding CommandBarViewModel.RegisterCardCommand}"
            />

                <AppBarButton 
            Icon="Refresh" 
            Label="Refresh" 
            Foreground="White" 
            Command="{Binding CommandBarViewModel.RefreshCardListCommand}" 
            />
            </CommandBar>

    </Page.BottomAppBar>
</Page>

xaml.cs:

デフォルトのテンプレートで、何も変更しないでください。

私はあなたの例外と UI バグを再現できません。ここに私の推測があります。プロジェクトのどこかで、HighContrastBorderスタイルのターゲットとして言及しています。他の場所で見つけて修正することをお勧めします。投稿されたコードは機能しています。私のビルドは 14316 デスクトップです。

アップデート

Visibility="{Binding ShowButton}"AppBarButton に追加し、xaml.cs のコンストラクターに追加this.DataContext = this;します。

以下を xaml.cs に追加します。

private bool _ShowButton = true;

        public bool ShowButton
        {
            get
            {
                return _ShowButton;
            }
            set
            {
                Set(ref _ShowButton, value);
            }
        }

        private void Set(ref bool _ShowButton, bool value, [CallerMemberName] string property = "")
        {
            _ShowButton = value;
            NotifyPropertyChanged(property);
        }

        public event PropertyChangedEventHandler PropertyChanged;

        private void NotifyPropertyChanged(String info)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(info));
            }
        }

値を変更するShowButtonと、それに応じて可視性が更新されます。

于 2016-04-12T13:40:10.817 に答える
1

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

Addコードの実行時にボタンまたはRefreshボタンが最初に非表示に設定されている場合、この問題を再現できます。

この問題を解決するには、x:Bind代わりに を使用できますBinding。{x:Bind} はコンパイル時に生成される専用コードを実行し、{Binding} は汎用のランタイム オブジェクト検査を使用します。

IsAddVisible最初にまたはに"false" (非表示) を設定IsRefreshListVisibleすると、一致した が生成されず、AppbarButtonを使用してエラーが発生しBindingます。たとえば、ボタンに非表示を設定し、ボタンに表示をx:Bind設定するために使用すると、 にボタン用のスペースがないことがわかり、ボタンがそれを置き換えます。これは私の意見を確認できます。初期化時に設定すると、このボタンは生成されません。RefreshAddRefreshCommandBarAddfalseAppbarButtonCommandbar

インストールされているコンポーネントは検出されませんでした。TargetName HighContrastBorder を解決できません

のテンプレートCommandBarを確認すると、の中にRectangle名前が付いていることがわかります。HighContrastBorderCommandBar

HighContrastBorderまたは、ライブ ビジュアル ツリーを使用して、コードの実行中にこれを見つけることができます。

ここに画像の説明を入力

ご覧のとおりRectangleContentRootCommandBarです。

この問題もテキストの途切れの問題も再現できません。MVVM を使用していますが、MVVMLight を使用して問題をテストしていません。サンプルを共有できるかもしれません。

于 2016-04-13T09:45:31.257 に答える