2012-05-10 18 views
2

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

 // 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によって自動的に作成されプッシュされる新しいDialogViewControllerは例外です。

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

答えて

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); 
    } 
} 

うまくいけば、これはそこに誰かリッテ時間を節約することができます...

1

この作業を取得するためには、私はそれが通常のUITableViewControllerに返すことMakeViewControllerメソッドをオーバーライドしなければならなかったとのUIViewControllerをキャストは、私の編集をしてください。

protected override UIViewController MakeViewController() 
{ 
    var vc = (UITableViewController) base.MakeViewController(); 

    vc.TableView.BackgroundView = null; 
    vc.View.BackgroundColor = UIColor.Red; //or whatever color you like 
    return vc; 
} 
関連する問題