<Window 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:WpfApplication1" xmlns:chartingToolkit="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit" x:Class="WpfApplication1.MainWindow" mc:Ignorable="d" Title="MainWindow" Height="637" Width="1889"> <Grid RenderTransformOrigin="0.505,0.844" Margin="0,0,0,19"> <CheckBox x:Name="cbFilter" Content="CheckBox" HorizontalAlignment="Left" Margin="15,410,0,0" VerticalAlignment="Top" Width="100" Height="25"/> <ComboBox x:Name="cbFilterMode" HorizontalAlignment="Left" Margin="95,410,0,0" VerticalAlignment="Top" Width="120"> <TextBlock>=</TextBlock> <TabItem/> </ComboBox> <TextBox x:Name="txtFilterValue" HorizontalAlignment="Left" Height="23" Margin="225,409,0,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="120"/> <GroupBox x:Name="groupBox" Header="GroupBox" HorizontalAlignment="Left" Margin="225,10,0,0" VerticalAlignment="Top" Width="1110" Height="385"> <DataGrid x:Name="dataGrid" HorizontalAlignment="Left" Margin="245,105,0,0" VerticalAlignment="Top" Height="230" Width="645"/> </GroupBox> <ListBox x:Name="listBox" HorizontalAlignment="Left" Height="385" Margin="10,10,0,0" VerticalAlignment="Top" Width="230" FontFamily="Segoe UI Black" Grid.Column="10"> <ListBox.ItemTemplate > <DataTemplate> <CheckBox x:Name="qqq" Content="{Binding }" IsChecked="{Binding IsChecked}" Click="CheckBox_Click"/> </DataTemplate> </ListBox.ItemTemplate> </ListBox> </Grid> 

It turns out to display only all at once, and how to do that would be displayed one by one (that is, if checkBox == true, then we derive this measurement from cube)

  private void CheckBox_Click(object sender, RoutedEventArgs e) { var cb = sender as CheckBox; var item = cb.IsChecked; listBox.SelectedItem = item; if (listBox.SelectedIndex==0) return; // первая часть запроса: количсество обращений string query = "SELECT NON EMPTY { [Measures].[Число Подписки] } ON COLUMNS, NON EMPTY {("; // если установлен фильтр - добавляем его // перебираем все отмеченные измерения и добавляем их к запросу foreach (string i in listBox.Checked) { query += " " + i.ToString() + ".ALLMEMBERS *"; } // удаляем последний пробел со звездочкой query = query.Remove(query.Length - 2); //финальная часть запроса query += " )} DIMENSION PROPERTIES MEMBER_CAPTION, MEMBER_UNIQUE_NAME ON ROWS FROM [Почта] CELL PROPERTIES VALUE, BACK_COLOR, FORE_COLOR, FORMATTED_VALUE, FORMAT_STRING, FONT_NAME, FONT_SIZE, FONT_FLAGS"; UpdateChart(query); } 

    1 answer 1

    You can use Linq by selecting all items that have IsChecked == true

    As an example: A ListBox with several items that have an IsChecked property. Those elements are selected for which IsChecked == true

    XAML

     <ListBox x:Name="CheckBoxes" ItemsSource="{Binding Items}"> <ListBox.ItemTemplate> <DataTemplate> <CheckBox IsChecked="{Binding IsChecked}" /> </DataTemplate> </ListBox.ItemTemplate> </ListBox> 

    CODE

     public class CheckBoxViewModel { public CheckBoxViewModel(bool isChecked) { IsChecked = isChecked; } public bool IsChecked { get; set; } } public class Content { public Content() { items = new List<CheckBoxViewModel> { new CheckBoxViewModel(true), new CheckBoxViewModel(true), new CheckBoxViewModel(true), new CheckBoxViewModel(true), new CheckBoxViewModel(false), new CheckBoxViewModel(true), new CheckBoxViewModel(false) }; } readonly IEnumerable<CheckBoxViewModel> items; public IEnumerable<CheckBoxViewModel> Items { get { return items; } } } public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); DataContext = new Content(); CheckBoxes.MouseDoubleClick += (s, e) => { // Получаем список элементов, у которых IsChecked == true var items = CheckBoxes.Items.Cast<CheckBoxViewModel>().Where(x => x.IsChecked); }; } }