기본적으로 XAML
은 표준 XML
을 충족하지만이 기능을 사용하려면 외부 라이브러리가 필요합니다. 예 : Microsoft XAML Toolkit CTP
(download). 문서의 모든 Control
에
// Previously adding the library
using Microsoft.Xaml.Tools.XamlDom;
XamlDomObject rootObject = XamlDomServices.Load("MainWindow.xaml");
foreach (XamlDomObject domObject in rootObject.DescendantsAndSelf())
{
MessageBox.Show(domObject.Type.ToString());
}
설정 Background
: 항목의 목록을 표시 간단한 예를 들어,
private void Window_ContentRendered(object sender, EventArgs e)
{
XamlDomObject rootObject = XamlDomServices.Load("MainWindow.xaml");
foreach (XamlDomObject objectNode in
from control in rootObject.DescendantsAndSelf(typeof(TextBlock))
where control.HasMember("Text")
select control)
{
objectNode.SetMemberValue("Text", "MyInsertedText");
}
XamlDomServices.Save(rootObject, "NewFile.xaml");
}
:
이
XamlDomObject rootObject = XamlDomServices.Load("MainWindow.xaml");
foreach (XamlDomObject objectNode in
from control in rootObject.DescendantsAndSelf(typeof(Control))
where !control.HasMember("Background")
select control)
{
objectNode.SetMemberValue("Background", "Red");
}
XamlDomServices.Save(rootObject, "NewFile.xaml");
를 들어 Text
특성의 값을 대체, 나는 예제를 사용
파일 Input
:
<Window x:Class="XAMLdom.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525" ContentRendered="Window_ContentRendered">
<Grid>
<TextBlock Text="SomeText" Width="100" Height="30" />
</Grid>
</Window>
파일 Output
는 :
<?xml version="1.0" encoding="utf-8"?>
<Window xml:base="file:///C:/Documents and Settings/Kanc/мои документы/visual studio 2010/Projects/XAMLdom/XAMLdom/bin/Debug/MainWindow.xaml" x:Class="XAMLdom.MainWindow" Title="MainWindow" Height="350" Width="525" ContentRendered="Window_ContentRendered" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid>
<TextBlock Text="MyInsertedText" Width="100" Height="30" />
</Grid>
</Window>
나는 당신이 원하는 것을 정확히 모르겠다. 그러나 여러 TextBlock 요소 텍스트를 동시에 변경한다면, 요소를 공통 속성에 바인딩하고 필요에 따라 속성을 수정하는 것을 고려해야한다. – Killingsworth
우리는 Visual Studio addin 같은 xaml 파일 내에서 Text = ""같은 요소를 자동으로 바꾸기를 원합니다. – Creator
죄송합니다. 내가 도울 수 있기를 바란다. 그러나 나는 내가 전에 그와 같은 무엇이라도 필요로했다라고 생각하지 않는다 (ctrl + r 외에). – Killingsworth