Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用PowerShell更改并保存XAML ResourceDictionary_Xaml_Powershell - Fatal编程技术网

使用PowerShell更改并保存XAML ResourceDictionary

使用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.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="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'))