2012-05-10 8 views
2

MonoTouch.Dialog를 사용하여 설정과 유사한 페이지를 만듭니다. 아래 linq는 RootElements 세트를 만들고 각 섹션에는 RadioEventElements (OnSelected 이벤트를 추가하기 위해 만든 RadioElement의 서브 클래스) 세트가있는 섹션이 하나씩 있습니다.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() 
      }); 
      // ... 
     }  

내가 구현 한 설정 중 하나는 현재 앱의 다양한 화면에 대한 배경색 인 "테마"입니다. 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에 반환하는있는 UIViewController를 MakeViewController 방법을 무시하고 캐스팅했다 ... 거기 밖으로 litte 시간을 사람을 절약 할 수 있습니다 , 그럼 내 편집을하십시오.

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; 
} 
관련 문제