2

MonoTouch.Dialog を使用して、設定のようなページを作成しています。以下の linq は、RadioEventElements (OnSelected イベントを追加するために作成した RadioElement のサブクラス) のセットを持つ 1 つのセクションを持つ RootElements のセットを作成します。

        // initialize other phone settings by creating a radio element list for each phone setting
        var elements = (from ps in PhoneSettings.Settings.Keys select (Element) new RootElement(ps, new RadioGroup(null, 0))).ToList();

        // loop through the root elements we just created and create their substructure
        foreach (RootElement rootElement in elements)
        {
            rootElement.Add(new Section()
            {
                (from val in PhoneSettings.Settings[rootElement.Caption].Values select (Element) new RadioEventElement(val.Name)).ToList()
            });
            // ...
        }       

私が実装する設定の 1 つは「テーマ」です。これは現在、アプリ内のさまざまな画面の背景色にすぎません。TableView.BackgroundColor プロパティを目的の色に設定することで、すべてのページを正しくスタイルできます...ラジオ グループに移動するときに、親 DialogViewController によって自動的に作成およびプッシュされる新しい DialogViewControllers を除きます。

この子 DialogViewController のスタイルを設定する (または少なくとも背景色を設定する) 方法はありますか?

4

2 に答える 2

4

簡単な質問をする前に、アセンブリ ブラウザをもっと使う必要があります :-)

幸いなことに、RootElement には、まさにこの目的のために、PrepareDialogViewController という名前の仮想メソッドがあります。必要な作業は、RootElement の単純なサブクラスを作成し、このメソッドをオーバーライドして目的の動作を実現することだけでした。

public class ThemedRootElement : RootElement 
{    
    public ThemedRootElement(string caption) : base (caption)
    {
    }

    public ThemedRootElement(string caption, Func<RootElement, UIViewController> createOnSelected) : base (caption, createOnSelected)
    {
    }

    public ThemedRootElement(string caption, int section, int element) : base (caption, section, element)
    {
    }

    public ThemedRootElement(string caption, Group group) : base (caption, group)
    {
    }

    protected override void PrepareDialogViewController(UIViewController dvc)
    {
        dvc.View.BackgroundColor = UIColorHelper.FromString(App.ViewModel.Theme.PageBackground);
        base.PrepareDialogViewController(dvc);
    }
}

うまくいけば、これは誰かが少し時間を節約するのに役立ちます...

于 2012-05-10T18:17:42.620 に答える