使用PowerShell更改并保存XAML ResourceDictionary
我有ResourceDictionary.xaml文件使用PowerShell更改并保存XAML ResourceDictionary,xaml,powershell,Xaml,Powershell,我有ResourceDictionary.xaml文件 <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:MyApp"> <Style x:Key="GridStyle" Tar
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:MyApp">
<Style x:Key="GridStyle" TargetType="Grid">
<Setter Property="Background" Value="Red"></Setter>
</Style>
<x:String x:Key="AppTitle">My App</x:String>
</ResourceDictionary>
我的应用程序
我想更改背景属性和AppTitle
输出ResourceDictionary2.xaml
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:MyApp">
<Style x:Key="GridStyle" TargetType="Grid">
<Setter Property="Background" Value="Green"></Setter>
</Style>
<x:String x:Key="AppTitle">My App 2</x:String>
</ResourceDictionary>
我的应用程序2
如何使用Power Shell执行此操作?将文件读取为XML文件,更改值,然后将其保存回文件:
[xml]$xml=获取内容“C:\path\to\ResourceDictionary.xaml”
$xml.ResourceDictionary.Style.Setter.Value='Green'
$xml.ResourceDictionary.#text'=“我的应用程序2”
$xml.Save('C:\path\to\Output ResourceDictionary2.xaml'))