티스토리 뷰
리소스를 이용해서 문자열 작업할 때 사용하는 방법이다.
1. DynamicResource
/// <summary>
/// 다이나믹 리소스
/// </summary>
public class DynamicResource : DynamicObject
{
/// <summary>
/// 윈도우 리소스로더
/// </summary>
Windows.ApplicationModel.Resources.ResourceLoader _rl;
/// <summary>
/// 리소스 전체 이름
/// </summary>
public string ResourceName { get; set; }
/// <summary>
/// 이름으로 호출
/// </summary>
/// <param name="binder"></param>
/// <param name="result"></param>
/// <returns></returns>
public override bool TryGetMember(GetMemberBinder binder, out object result)
{
string str = string.Empty;
if (Windows.ApplicationModel.DesignMode.DesignModeEnabled == false)
{
if (_rl == null)
{
_rl = Windows.ApplicationModel.Resources.ResourceLoader.GetForCurrentView(ResourceName);
}
str = _rl.GetString(binder.Name);
if (string.IsNullOrEmpty(str) == true)
{
str = string.Empty;
}
}
else
{
str = binder.Name;
}
result = str;
return true;
}
/// <summary>
/// 프로퍼티로 호출
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public string this[string id]
{
get
{
string str = string.Empty;
if (Windows.ApplicationModel.DesignMode.DesignModeEnabled == false)
{
if (_rl == null)
{
_rl = Windows.ApplicationModel.Resources.ResourceLoader.GetForCurrentView(ResourceName);
}
str = _rl.GetString(id);
if (string.IsNullOrEmpty(str) == true)
{
str = string.Empty;
}
}
else
{
//디자인 타임에서는 키값을 반환
str = id;
}
return str;
}
}
}
2. App.xaml
xmlns:CPCommons="using:CrossPlatform.Infrastructure.StoreApp.Commons"
...
<CPCommons:DynamicResource x:Key="DResource" ResourceName="ScreenshotAutoCut.PCL.en.UIResources"/>
3. xaml에서 사용하기
<TextBlock Style="{StaticResource SubheaderTextBlockStyle}" Grid.Row="1" Margin="0,10,0,0" TextWrapping="Wrap"
Text="{Binding [tx_please_add_screenshots_folder], Source={StaticResource DResource}}"/>
<TextBlock Style="{StaticResource TitleTextBlockStyle}" Grid.Row="2" Margin="0,10,0,0"
Text="{Binding [tx_description], Source={StaticResource DResource}}"/>
<TextBlock Style="{StaticResource BodyTextBlockStyle}" Grid.Row="3"
Text="{Binding [tx_click_the_add_folder_button], Source={StaticResource DResource}}" >
4. cs에서 사용하기
//리소스 타입 입력 - dynamic 키워드가 중요
dynamic DR = App.Current.Resources["DResource"];
var test = DR.tx_please_add_screenshots_folder;
System.Diagnostics.Debug.WriteLine(test);
'Previous Platforms' 카테고리의 다른 글
디아블로3 아이템 자랑은 Screenshot AutoCut로! (0) | 2014.05.15 |
---|---|
Windows Store Apps, Error: The certificate specified has expired (0) | 2014.05.06 |
Windows 8 app add advertising by AdDuplex (0) | 2014.04.19 |
Screenshot AutoCut Privacy Policy (0) | 2014.04.17 |
Screenshot AutoCut Help (0) | 2014.04.17 |
- Total
- Today
- Yesterday
- #MVVM
- Visual Studio 2022
- Build 2016
- Cross-platform
- .net 5.0
- WPF
- Always Encrypted
- ComboBox
- Bot Framework
- #prism
- uno-platform
- XAML
- Microsoft
- visual studio 2019
- kiosk
- UWP
- dotNETconf
- ef core
- windows 11
- Behavior
- Windows 10
- IOT
- uno platform
- C#
- #uwp
- MVVM
- .net
- PRISM
- LINQ
- #Windows Template Studio
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |