몇 가지 범용 응용 프로그램 막대 메뉴 항목을 활성화하거나 비활성화하기 위해 모바일 응용 프로그램의 기본 페이지를 추가 부울 종속성 속성으로 구성합니다. 이러한 종속성 속성을 기본값에 대한 메타 데이터로 등록하더라도 값에 대한 설정자가 항상 호출되지는 않습니다.DefaultStyleKey를 설정하면 "ArgumentException : 값이 예상 범위 내에 들지 않습니다."
public class MyPageBase : PhoneApplicationPage
{
public MyBasePage() {
DefaultStyleKey = typeof(MyPageBase);
}
public static readonly DependencyProperty ShowSettingsMenuItemProperty =
DependencyProperty.Register(
"ShowSettingsMenuItem",
typeof(bool),
typeof(MyPageBase),
new PropertyMetadata(true, ShowSettingsMenuItemChanged));
public static readonly DependencyProperty ShowLogoutMenuItemProperty =
DependencyProperty.Register(
"ShowLogoutMenuItem",
typeof(bool),
typeof(MyPageBase),
new PropertyMetadata(true, ShowLogoutMenuItemChanged));
}
다음 두 속성을 값으로 설정하는 페이지의 기본 "테마"를 만들어야한다고 가정했습니다. Themes 폴더와 Generic.xaml 파일을 만들고 Build Action을 Page로 설정했습니다. 그런 다음 메타 데이터에서 두 속성을 기본값으로 설정하는 페이지 유형을 대상으로하는 매우 간단한 스타일을 정의했습니다. 기본 페이지의 생성자의 첫 번째 행이 명중 할 때
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:view="clr-namespace:MyApplication.View">
<Style TargetType="view:MyPageBase">
<Setter Property="ShowLogoutMenuItem" Value="True" />
<Setter Property="ShowSettingsMenuItem" Value="True" />
</Style>
</ResourceDictionary>
은 그러나, 다음과 같은 예외가 발생합니다 :
System.ArgumentException : 값이 예상 범위 내에 있지 않습니다.
ILSpy에서 컴파일 된 라이브러리를 검사했으며 리소스 폴더에 themes/generic.xaml을 포함하여 프로젝트의 모든 XAML 파일이 포함 된 g.resources 폴더가 포함되어 있습니다. 이러한 종속성 속성의 기본값을 올바르게 초기화하기 위해 수행해야 할 작업은 무엇입니까?
오른쪽 근처가 보입니다. setter가 호출되는 것이 아니었지만 값이 기본값에서 변경되지 않았기 때문에 내 "변경"기능이 아무 것도 수행하지 못했습니다. 나는 부울을 테스트하고로드시 실제 값에 대해 초기화를 한 번 실행하기로 결정했습니다. – lsuarez