Hello,
Welcome to Microsoft Q&A!
If I understand you correctly, you are trying to prevent the UIElements from scaling if user has a different scale value than 100% on his device, right? You just make the UIElements still be shown in 100% scale value.
Currently, there is no way to turn off scaling on PC devices. What you could do is to override the automatic scaling of text and UI as the scale factor changes by checking the DisplayInformation.RawPixelsPerViewPixel property. You need to override the size for all the elements to achieve what you want.
I've made a simple demo about this. The sample contains a TextBlock and a Button. Both the sizes are 300*300. When the scale value changes, them will still looks the same as they are in 100% scale.
Xaml:
<StackPanel>
<TextBlock x:Name="MyTextBlock" Text="123213" FontSize="45" Width="300" Height="300"/>
<Button x:Name="MyButton" Content="Click" Click="Button_Click" Width="300" Height="300"/>
</StackPanel>
Code-behind:
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
this.Loaded += MainPage_Loaded;
var size = new Size(1920, 1080);
ApplicationView.PreferredLaunchViewSize = size;
ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.PreferredLaunchViewSize;
Window.Current.CoreWindow.SizeChanged += (s, e) => { ApplicationView.GetForCurrentView().TryResizeView(size); };
DisplayInformation displayInformation = DisplayInformation.GetForCurrentView();
displayInformation.DpiChanged += DisplayInformation_DpiChanged;
}
private void DisplayInformation_DpiChanged(DisplayInformation sender, object args)
{
reSetSize();
}
private void MainPage_Loaded(object sender, RoutedEventArgs e)
{
reSetSize();
}
private void reSetSize()
{
DisplayInformation displayInformation = DisplayInformation.GetForCurrentView();
double rawPixelsPerViewPixel = displayInformation.RawPixelsPerViewPixel;
// Set the override rectangle size by taking our desired
// size in raw pixels and converting it to view pixels.
const double rectSizeInRawPx = 300; //300 is the original size of the button
double rectSizeInViewPx = rectSizeInRawPx / rawPixelsPerViewPixel; //get new size for the new scaling
MyButton.Width = rectSizeInViewPx;
MyButton.Height = rectSizeInViewPx;
// override text font size
double fontSizeInRawPx = 45 * 96 / 72; // 45 is the original fontsize
double fontSizeInViewPx = fontSizeInRawPx / rawPixelsPerViewPixel;
MyTextBlock.FontSize = fontSizeInViewPx;
}
private void Button_Click(object sender, RoutedEventArgs e)
{
}
}
You could also refer to the official sample DpiScaling about Overriding default scaling of UI elements
Thank you.
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.