C
C#17mo ago
Donut5162

WPF MenuItems

For some reason my menu items expand towards the left instead of to the right. No other apps on my device do it like this so I don't think its a system setting. Any ideas on how I can fix this?
1 Reply
Donut5162
Donut5162OP17mo ago
Okay nevermind, for some reason Windows thinks right-handed people get this ^ and left handed people get menu items that are correctly aligned for WPF apps. This is a solution I found on stackoverflow in case anyone is curious:
private static void SetDropDownMenuToBeRightAligned() {
var menuDropAlignmentField = typeof(SystemParameters).GetField("_menuDropAlignment", BindingFlags.NonPublic | BindingFlags.Static);
Action setAlignmentValue = () =>
{
if (SystemParameters.MenuDropAlignment && menuDropAlignmentField != null) menuDropAlignmentField.SetValue(null, false);
};

setAlignmentValue();

SystemParameters.StaticPropertyChanged += (sender, e) =>
{
setAlignmentValue();
};
}
private static void SetDropDownMenuToBeRightAligned() {
var menuDropAlignmentField = typeof(SystemParameters).GetField("_menuDropAlignment", BindingFlags.NonPublic | BindingFlags.Static);
Action setAlignmentValue = () =>
{
if (SystemParameters.MenuDropAlignment && menuDropAlignmentField != null) menuDropAlignmentField.SetValue(null, false);
};

setAlignmentValue();

SystemParameters.StaticPropertyChanged += (sender, e) =>
{
setAlignmentValue();
};
}
Want results from more Discord servers?
Add your server