Имею ряд кнопок, которые переключают страницу приложения. У кнопок есть 2 состояния, нажатая и нет, для каждого состояния реализован стиль Menu - обычная и MenuIn - нажатая (то есть у пользователя открыта сейчас именно эта страница). В стилях изменяется только цвет.
Сейчас у меня каждая кнопка привязана к обработчику, который с помощью switch, по названию кнопки выполняет необходимые действия, а именно открывает нужную страницу, задает всем не активным кнопкам стиль Menu и кнопке текущего раздела задает стиль MenuIn. В итоге у меня получается огромная портянка повторяющихся строк.
Как грамотно сократить код, может в стиле как то определять нажата кнопка или нет, может еще что?
private void ButtonEvent(string name)
{
switch (name)
{
case "ChangeBg":
BackgroundEvent.Restart();
break;
case "HomeBtn":
HomeBtn.Style = (Style) Application.Current.Resources["MenuIn"];
NewsBtn.Style = (Style) Application.Current.Resources["Menu"];
AlertsBtn.Style = (Style) Application.Current.Resources["Menu"];
InvasionsBtn.Style = (Style) Application.Current.Resources["Menu"];
SettingsBtn.Style = (Style) Application.Current.Resources["Menu"];
InfoBtn.Style = (Style) Application.Current.Resources["Menu"];
TradeBtn.Style = (Style) Application.Current.Resources["Menu"];
ActMissionsBtn.Style = (Style) Application.Current.Resources["Menu"];
MainFrame.Navigate(new Uri("View/HomePage.xaml", UriKind.Relative));
break;
case "NewsBtn":
HomeBtn.Style = (Style) Application.Current.Resources["Menu"];
NewsBtn.Style = (Style) Application.Current.Resources["MenuIn"];
AlertsBtn.Style = (Style) Application.Current.Resources["Menu"];
InvasionsBtn.Style = (Style) Application.Current.Resources["Menu"];
SettingsBtn.Style = (Style) Application.Current.Resources["Menu"];
InfoBtn.Style = (Style) Application.Current.Resources["Menu"];
TradeBtn.Style = (Style) Application.Current.Resources["Menu"];
ActMissionsBtn.Style = (Style) Application.Current.Resources["Menu"];
//MyPopup.IsOpen = true;
MainFrame.Navigate(new Uri("View/NewsPage.xaml", UriKind.Relative));
break;
case "AlertsBtn":
HomeBtn.Style = (Style) Application.Current.Resources["Menu"];
NewsBtn.Style = (Style) Application.Current.Resources["Menu"];
AlertsBtn.Style = (Style) Application.Current.Resources["MenuIn"];
InvasionsBtn.Style = (Style) Application.Current.Resources["Menu"];
SettingsBtn.Style = (Style) Application.Current.Resources["Menu"];
InfoBtn.Style = (Style) Application.Current.Resources["Menu"];
TradeBtn.Style = (Style) Application.Current.Resources["Menu"];
ActMissionsBtn.Style = (Style) Application.Current.Resources["Menu"];
//MyPopup.IsOpen = false;
//BodyFrame.Navigate(new Uri("Pages/AlertsPage.xaml", UriKind.Relative));
break;
case "TradeBtn":
HomeBtn.Style = (Style) Application.Current.Resources["Menu"];
NewsBtn.Style = (Style) Application.Current.Resources["Menu"];
AlertsBtn.Style = (Style) Application.Current.Resources["Menu"];
InvasionsBtn.Style = (Style) Application.Current.Resources["Menu"];
SettingsBtn.Style = (Style) Application.Current.Resources["Menu"];
InfoBtn.Style = (Style) Application.Current.Resources["Menu"];
TradeBtn.Style = (Style) Application.Current.Resources["MenuIn"];
ActMissionsBtn.Style = (Style) Application.Current.Resources["Menu"];
//BodyFrame.Navigate(new Uri("Pages/TradePage.xaml", UriKind.Relative));
break;
case "InvasionsBtn":
HomeBtn.Style = (Style) Application.Current.Resources["Menu"];
NewsBtn.Style = (Style) Application.Current.Resources["Menu"];
AlertsBtn.Style = (Style) Application.Current.Resources["Menu"];
InvasionsBtn.Style = (Style) Application.Current.Resources["MenuIn"];
SettingsBtn.Style = (Style) Application.Current.Resources["Menu"];
InfoBtn.Style = (Style) Application.Current.Resources["Menu"];
TradeBtn.Style = (Style) Application.Current.Resources["Menu"];
ActMissionsBtn.Style = (Style) Application.Current.Resources["Menu"];
//BodyFrame.Navigate(new Uri("Pages/InvasionsPage.xaml", UriKind.Relative));
break;
case "InfoBtn":
HomeBtn.Style = (Style) Application.Current.Resources["Menu"];
NewsBtn.Style = (Style) Application.Current.Resources["Menu"];
AlertsBtn.Style = (Style) Application.Current.Resources["Menu"];
InvasionsBtn.Style = (Style) Application.Current.Resources["Menu"];
SettingsBtn.Style = (Style) Application.Current.Resources["Menu"];
InfoBtn.Style = (Style) Application.Current.Resources["MenuIn"];
TradeBtn.Style = (Style) Application.Current.Resources["Menu"];
ActMissionsBtn.Style = (Style) Application.Current.Resources["Menu"];
//BodyFrame.Navigate(new Uri("Pages/InfoPage.xaml", UriKind.Relative));
break;
case "SettingsBtn":
HomeBtn.Style = (Style) Application.Current.Resources["Menu"];
NewsBtn.Style = (Style) Application.Current.Resources["Menu"];
AlertsBtn.Style = (Style) Application.Current.Resources["Menu"];
InvasionsBtn.Style = (Style) Application.Current.Resources["Menu"];
InfoBtn.Style = (Style) Application.Current.Resources["Menu"];
SettingsBtn.Style = (Style) Application.Current.Resources["MenuIn"];
TradeBtn.Style = (Style) Application.Current.Resources["Menu"];
ActMissionsBtn.Style = (Style) Application.Current.Resources["Menu"];
//BodyFrame.Navigate(new Uri("Pages/SettingsPage.xaml", UriKind.Relative));
break;
case "ActMissionsBtn":
HomeBtn.Style = (Style) Application.Current.Resources["Menu"];
NewsBtn.Style = (Style) Application.Current.Resources["Menu"];
AlertsBtn.Style = (Style) Application.Current.Resources["Menu"];
InvasionsBtn.Style = (Style) Application.Current.Resources["Menu"];
InfoBtn.Style = (Style) Application.Current.Resources["Menu"];
SettingsBtn.Style = (Style) Application.Current.Resources["Menu"];
TradeBtn.Style = (Style) Application.Current.Resources["Menu"];
ActMissionsBtn.Style = (Style) Application.Current.Resources["MenuIn"];
//BodyFrame.Navigate(new Uri("Pages/ActiveMissionsPage.xaml", UriKind.Relative));
break;
}
}

HomeBtn.Style = (Style) Application.Current.Resources[name == "HomeBtn" ? "MenuIn" : "Menu"];– user181245 Jul 11 '17 at 20:12ItemsControl? Есть отличная статья о том, как можно организовать навигацию, ссылка – Jul 11 '17 at 20:26ItemsControlлучше будет использоватьListBox, там реализован функционалSelectedItem– Jul 11 '17 at 20:28ListBox'е реализовать подобное расположение кнопок? Ведь у меня 2 (маленькие) кнопки вверху имеют другое расположение, а также две кнопки снизу, отделенные от всех основных. Лист получится мне все это сложит построчно (что мне не нужно) – EvgeniyZ Jul 11 '17 at 20:33