Hi,
you can use for instance of window an additional parameter (in ctor) to set string resource like in following demo:
XAML MainWindow:
<Window x:Class="WpfApp1.Window013"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp013"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="400">
<Window.DataContext>
<local:ViewModel/>
</Window.DataContext>
<StackPanel>
<Button Content="Window 1" Command="{Binding}" CommandParameter="1" Width="200" Margin="5"/>
<Button Content="Window 2" Command="{Binding}" CommandParameter="2" Width="200" Margin="5"/>
</StackPanel>
</Window>
ViewModel:
using System;
using System.Windows;
using System.Windows.Input;
namespace WpfApp013
{
public class ViewModel : ICommand
{
public void Execute(object parameter)
{
WpfApp1.Window013A wnd;
switch (parameter.ToString())
{
case "1":
wnd = new WpfApp1.Window013A("Title 1");
wnd.Show();
break;
case "2":
wnd = new WpfApp1.Window013A("Title 2");
wnd.Show();
break;
default:
break;
}
}
public event EventHandler CanExecuteChanged;
public bool CanExecute(object parameter) => true;
}
}
Second Window with Title set in MainWindow:
<Window x:Class="WpfApp1.Window013A"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp1"
xmlns:clr="clr-namespace:System;assembly=mscorlib"
mc:Ignorable="d"
Title="{StaticResource Title}" Height="450" Width="800">
<StackPanel>
<Button Content="Button"
Width="100"
Margin="5" HorizontalAlignment="Left"
ToolTipService.InitialShowDelay="0"
ToolTipService.BetweenShowDelay="0"
ToolTipService.ShowDuration="60000">
<Button.ToolTip>
<ToolTip x:Name="helpButtonTooltip"
Width="240"
ToolTipService.InitialShowDelay="0">
<TextBlock Text="{StaticResource Title}"
HorizontalAlignment="Stretch"
VerticalAlignment="Center"
Foreground="Red"
FontSize="18px"
FontStretch="UltraExpanded" />
</ToolTip>
</Button.ToolTip>
</Button>
</StackPanel>
</Window>
And CodeBehind:
using System.Windows;
namespace WpfApp1
{
public partial class Window013A : Window
{
public Window013A(string title)
{
this.Resources.Add("Title", title);
InitializeComponent();
}
}
}
Result: