Values in the dropdown not visible

Hi, I have the following codes:

CorrMarket.cs:

namespace TradingApp
{
    public class CorrMarket
    {
        public string? Names { get; set; }
    }
}

ViewModel.cs:

using System.Collections.ObjectModel;
using Npgsql;
using Syncfusion.Windows.Tools.Controls;


namespace TradingApp
{
    public class ViewModel
    {
        private string _countrySavedValue = string.Empty;
        private string _marketSavedValue = string.Empty;
        private string _deliverymonthSavedValue = string.Empty;
        private double _corrSavedValue;
        private string _corrmarketsSavedValue = string.Empty;
        public ObservableCollection<Country> Countries { get; set; }
        public ObservableCollection<Market> Markets { get; set; }
        public ObservableCollection<DeliveryMonth> DeliveryMonths { get; set; }
        public ObservableCollection<CorrMarket> CorrMarkets { get; set; }
        public string CountrySavedValue
        {
            get { return _countrySavedValue; }
            set { _countrySavedValue = value; }
        }
        public string MarketSavedValue
        {
            get { return _marketSavedValue; }
            set { _marketSavedValue = value; MakeDeliveryMonthQuery(); }
        }
        public string DeliveryMonthSavedValue
        {
            get { return _deliverymonthSavedValue; }
            set { _deliverymonthSavedValue = value; }
        }
        public double CorrSavedValue
        {
            get { return _corrSavedValue; }
            set { _corrSavedValue = value; MakeCorrMarketsQuery(); }
        }
        public string CorrMarketsSavedValue
        {
            get { return _corrmarketsSavedValue; }
            set { _corrmarketsSavedValue = value; }
        }
        private void MakeDeliveryMonthQuery()
        {
            DeliveryMonths.Clear();
            NpgsqlConnection conn2 = new NpgsqlConnection("Host=192.168.1.2; Port=5432; Database=tradingapp; Username=vorlket; Password=Vcsokr.");
            conn2.Open();
            string query2 = "SELECT DISTINCT \"Delivery Month\" FROM Futures WHERE Name = '" + MarketSavedValue + "' ORDER BY \"Delivery Month\"";
            NpgsqlCommand cmd2 = new NpgsqlCommand(query2, conn2);
            NpgsqlDataReader reader2 = cmd2.ExecuteReader();
            while (reader2.Read())
            {
                DeliveryMonths.Add(new DeliveryMonth
                {
                    Month = reader2.GetString(0)
                });
            }
        }
        private void MakeCorrMarketsQuery()
        {
            CorrMarkets.Clear();
            NpgsqlConnection conn3 = new NpgsqlConnection("Host=192.168.1.2; Port=5432; Database=tradingapp; Username=vorlket; Password=Vcsokr.");
            conn3.Open();
            string query3 = "SELECT DISTINCT CONCAT_WS(', ', name_a, name_b) AS Names FROM Correlation WHERE correlation > " + CorrSavedValue + " OR correlation < " + (CorrSavedValue * -1);
            NpgsqlCommand cmd3 = new NpgsqlCommand(query3, conn3);
            NpgsqlDataReader reader3 = cmd3.ExecuteReader();
            while (reader3.Read())
            {
                CorrMarkets.Add(new CorrMarket
                {
                    Names = reader3.GetString(0)
                });
            }
        }
        public ViewModel()
        {
            Countries = new ObservableCollection<Country>();
            Markets = new ObservableCollection<Market>();
            DeliveryMonths = new ObservableCollection<DeliveryMonth>();
            CorrMarkets = new ObservableCollection<CorrMarket>();
            LoadData();
        }
        private void LoadData()
        {
            NpgsqlConnection conn = new NpgsqlConnection("Host=192.168.1.2; Port=5432; Database=tradingapp; Username=vorlket; Password=Vcsokr.");
            conn.Open();
            string query = "SELECT DISTINCT Country FROM EconomicCalendar ORDER BY Country";
            NpgsqlCommand cmd = new NpgsqlCommand(query, conn);
            NpgsqlDataReader reader = cmd.ExecuteReader();
            while (reader.Read())
            {
                Countries.Add(new Country
                {
                    Name = reader.GetString(0)
                });
            }


            NpgsqlConnection conn1 = new NpgsqlConnection("Host=192.168.1.2; Port=5432; Database=tradingapp; Username=vorlket; Password=Vcsokr.");
            conn1.Open();
            string query1 = "SELECT DISTINCT Name FROM Futures ORDER BY Name";
            NpgsqlCommand cmd1 = new NpgsqlCommand(query1, conn1);
            NpgsqlDataReader reader1 = cmd1.ExecuteReader();
            while (reader1.Read())
            {
                Markets.Add(new Market
                {
                    Name = reader1.GetString(0)
                });
            }
        }
    }
}

MainWindow.xaml.cs:

using Syncfusion.Windows.Shared;
using Syncfusion.Windows.Tools.Controls;
using System.Windows;


namespace TradingApp
{
    public partial class MainWindow : Window
    {
        string selectedCountry = "";
        string selectedMarket = "";
        string selectedDeliveryMonth = "";
        Date selectedStartDate = new Date();
        Date selectedEndDate = new Date();
        double selectedCorr = 0.00;
        string selectedCorrMarkets = "";


        public MainWindow()
        {
            InitializeComponent();
        }
        private void DropDownMenuItem_CountryClick(object sender, RoutedEventArgs e)
        {
            selectedCountry = (sender as DropDownMenuItem)?.Header?.ToString() ?? string.Empty;
            CountryDropDown.Label = selectedCountry;
            viewModel.CountrySavedValue = selectedCountry;
        }
        private void DropDownMenuItem_MarketClick(object sender, RoutedEventArgs e)
        {
            selectedMarket = (sender as DropDownMenuItem)?.Header?.ToString() ?? string.Empty;
            MarketDropDown.Label = selectedMarket;
            viewModel.MarketSavedValue = selectedMarket;
        }
        private void DropDownMenuItem_DeliveryMonthClick(object sender, RoutedEventArgs e)
        {
            selectedDeliveryMonth = (sender as DropDownMenuItem)?.Header?.ToString() ?? string.Empty;
            DeliveryMonthDropDown.Label = selectedDeliveryMonth;
            viewModel.DeliveryMonthSavedValue = selectedDeliveryMonth;
        }
        private void ButtonAdvItem_ChartButtonClick(object sender, RoutedEventArgs e)
        {
            string selectedMarket = viewModel.MarketSavedValue;
            string selectedDeliveryMonth = viewModel.DeliveryMonthSavedValue;


            ChartWindow chartWindow = new ChartWindow(selectedMarket, selectedDeliveryMonth);
            chartWindow.Title = $"{selectedMarket} - {selectedDeliveryMonth}";
            chartWindow.Show();
        }
        private void ButtonAdvItem_TableButtonClick(object sender, RoutedEventArgs e)
        {
            string selectedCountry = viewModel.CountrySavedValue;
            List<Date> startDates = DateCalendarEditStart.SelectedDatesList;
            List<Date> endDates = DateCalendarEditEnd.SelectedDatesList;
            Date selectedStartDate = startDates.Min();
            Date selectedEndDate = endDates.Max();


            TableWindow tableWindow = new TableWindow(selectedCountry, selectedStartDate, selectedEndDate);
            tableWindow.Title = $"{selectedCountry}";
            tableWindow.Show();
        }
        private void DoubleTextBox_ValueChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            selectedCorr = (double)e.NewValue;
            viewModel.CorrSavedValue = selectedCorr;
        }
        private void DropDownMenuItem_CorrMarketsClick(object sender, RoutedEventArgs e)
        {
            selectedCorrMarkets = (sender as DropDownMenuItem)?.Header?.ToString() ?? string.Empty;
            CorrMarketsDropDown.Label = selectedCorrMarkets;
            viewModel.CorrMarketsSavedValue = selectedCorrMarkets;
        }
        private void ButtonAdvItem_CorrChartButtonClick(object sender, RoutedEventArgs e)
        {
            string selectedCorrMarkets = viewModel.CorrMarketsSavedValue;


        }
    }
}

MainWindow.xaml:

<Window x:Class="TradingApp.MainWindow"
        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:TradingApp"
        xmlns:syncfusion="http://schemas.syncfusion.com/wpf"
        mc:Ignorable="d"
        Title="Trading App" Height="450" Width="800">
    <Window.DataContext>
        <local:ViewModel x:Name="viewModel"/>
    </Window.DataContext>
    <Grid>
        <syncfusion:TabControlExt Name="tabControlExt">
            <syncfusion:TabItemExt Header="Raw Data">
                <Grid Margin="10">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto"/>
                        <ColumnDefinition Width="*"/>
                    </Grid.ColumnDefinitions>
                    <Label Grid.Row="0" Grid.Column="0" HorizontalAlignment="Left" FontWeight="Bold">Market:</Label>
                    <StackPanel Grid.Row="0" Grid.Column="1" HorizontalAlignment="Left" Margin="0,0,0,0">
                        <syncfusion:DropDownButtonAdv IconHeight="1" IconWidth="1" SizeMode="Normal" x:Name="MarketDropDown" Label="Market">
                            <syncfusion:DropDownMenuGroup ScrollBarVisibility="Visible" ItemsSource="{Binding Markets}">
                                <syncfusion:DropDownMenuGroup.ItemTemplate>
                                    <DataTemplate>
                                        <syncfusion:DropDownMenuItem Header="{Binding Name}" HorizontalAlignment="Left" Click="DropDownMenuItem_MarketClick">
                                        </syncfusion:DropDownMenuItem>
                                    </DataTemplate>
                                </syncfusion:DropDownMenuGroup.ItemTemplate>
                            </syncfusion:DropDownMenuGroup>
                        </syncfusion:DropDownButtonAdv>
                    </StackPanel>
                    <Label Grid.Row="1" Grid.Column="0" HorizontalAlignment="Left" Margin="0,0,0,0" FontWeight="Bold">Delivery Month:</Label>
                    <StackPanel Grid.Row="1" Grid.Column="1" HorizontalAlignment="Left" Margin="0,0,0,0">
                        <syncfusion:DropDownButtonAdv IconHeight="1" IconWidth="1" SizeMode="Normal" x:Name="DeliveryMonthDropDown" Label="Delivery Month">
                            <syncfusion:DropDownMenuGroup ScrollBarVisibility="Visible" ItemsSource="{Binding DeliveryMonths}">
                                <syncfusion:DropDownMenuGroup.ItemTemplate>
                                    <DataTemplate>
                                        <syncfusion:DropDownMenuItem Header="{Binding Month}" HorizontalAlignment="Left" Click="DropDownMenuItem_DeliveryMonthClick">
                                        </syncfusion:DropDownMenuItem>
                                    </DataTemplate>
                                </syncfusion:DropDownMenuGroup.ItemTemplate>
                            </syncfusion:DropDownMenuGroup>
                        </syncfusion:DropDownButtonAdv>
                    </StackPanel>
                    <Label Grid.Row="2" Grid.Column="0" HorizontalAlignment="Left" Margin="0,0,0,0" FontWeight="Bold">Country:</Label>
                    <StackPanel Grid.Row="2" Grid.Column="1" HorizontalAlignment="Left" Margin="0,0,0,0">
                        <syncfusion:DropDownButtonAdv IconHeight="1" IconWidth="1" SizeMode="Normal" x:Name="CountryDropDown" Label="Country">
                            <syncfusion:DropDownMenuGroup ScrollBarVisibility="Visible" ItemsSource="{Binding Countries}">
                                <syncfusion:DropDownMenuGroup.ItemTemplate>
                                    <DataTemplate>
                                        <syncfusion:DropDownMenuItem Header="{Binding Name}" HorizontalAlignment="Left" Click="DropDownMenuItem_CountryClick">
                                        </syncfusion:DropDownMenuItem>
                                    </DataTemplate>
                                </syncfusion:DropDownMenuGroup.ItemTemplate>
                            </syncfusion:DropDownMenuGroup>
                        </syncfusion:DropDownButtonAdv>
                    </StackPanel>
                    <Label Grid.Row="3" Grid.Column="0" HorizontalAlignment="Left" Margin="0,0,0,0" FontWeight="Bold">Date:</Label>
                    <syncfusion:CalendarEdit Grid.Row="3" Grid.Column="1" Name="DateCalendarEditStart" HorizontalAlignment="Left" Margin="0,0,0,0" Height="200" Width="200" AllowMultiplySelection="True"/>
                    <syncfusion:CalendarEdit Grid.Row="3" Grid.Column="1" Name="DateCalendarEditEnd" HorizontalAlignment="Left" Margin="200,0,0,0" Height="200" Width="200" AllowMultiplySelection="True"/>
                    <syncfusion:ButtonAdv x:Name="ChartButton" Grid.Row="1" Grid.Column="1" Height="25" Width="200" IconHeight="1" IconWidth="1" SizeMode="Normal" VerticalAlignment="Top" HorizontalAlignment="Right" Label="Open Market Chart" Click="ButtonAdvItem_ChartButtonClick"/>
                    <syncfusion:ButtonAdv x:Name="TableButton" Grid.Row="4" Grid.Column="1" Height="25" Width="200" IconHeight="1" IconWidth="1" SizeMode="Normal" VerticalAlignment="Top" HorizontalAlignment="Right" Label="Open Economic Calendar Table" Click="ButtonAdvItem_TableButtonClick"/>
                </Grid>
            </syncfusion:TabItemExt>
            <syncfusion:TabItemExt Header="Correlation">
                <Grid Margin="10">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto"/>
                        <ColumnDefinition Width="*"/>
                    </Grid.ColumnDefinitions>
                    <Label Grid.Row="0" Grid.Column="0" HorizontalAlignment="Left" FontWeight="Bold">Correlation Cutoff:</Label>
                    <StackPanel Grid.Row="0" Grid.Column="1" HorizontalAlignment="Left" Margin="0,0,0,0">
                        <syncfusion:DoubleTextBox x:Name="doubleTextBox" Width="100" Height="25" MaxValue ="1.00" MinValue="-1.00" VerticalAlignment="Center" HorizontalAlignment="Center" ValueChanged="DoubleTextBox_ValueChanged"/>
                    </StackPanel>
                    <Label Grid.Row="1" Grid.Column="0" HorizontalAlignment="Left" Margin="0,0,0,0" FontWeight="Bold">Correlated Markets:</Label>
                    <StackPanel Grid.Row="1" Grid.Column="1" HorizontalAlignment="Left" Margin="0,0,0,0">
                        <syncfusion:DropDownButtonAdv IconHeight="1" IconWidth="1" SizeMode="Normal" x:Name="CorrMarketsDropDown" Label="Correlated Markets">
                            <syncfusion:DropDownMenuGroup ScrollBarVisibility="Visible" ItemsSource="{Binding CorrMarkets}">
                                <syncfusion:DropDownMenuGroup.ItemTemplate>
                                    <DataTemplate>
                                        <syncfusion:DropDownMenuItem Header="{Binding CorrMarkets}" HorizontalAlignment="Left" Click="DropDownMenuItem_CorrMarketsClick">
                                        </syncfusion:DropDownMenuItem>
                                    </DataTemplate>
                                </syncfusion:DropDownMenuGroup.ItemTemplate>
                            </syncfusion:DropDownMenuGroup>
                        </syncfusion:DropDownButtonAdv>
                    </StackPanel>
                    <syncfusion:ButtonAdv x:Name="CorrChartButton" Grid.Row="1" Grid.Column="1" Height="25" Width="200" IconHeight="1" IconWidth="1" SizeMode="Normal" VerticalAlignment="Top" HorizontalAlignment="Right" Label="Open Correlated Market Chart" Click="ButtonAdvItem_CorrChartButtonClick"/>
                </Grid>
            </syncfusion:TabItemExt>
        </syncfusion:TabControlExt>
    </Grid>
</Window>

Under the Correlation tab, when the Correlation Cutoff value is set, the Correlated Markets dropdown values are set but not visible. Could you please help me understanding what's going on? Thanks.


1 Reply 1 reply marked as answer

KJ Kook Jin Noh October 31, 2024 09:16 AM UTC

<syncfusion:DropDownMenuGroup.ItemTemplate>

    <DataTemplate>

        <syncfusion:DropDownMenuItem Header="{Binding Names}" HorizontalAlignment="Left" Click="DropDownMenuItem_CorrMarketsClick">

        </syncfusion:DropDownMenuItem>

    </DataTemplate>

</syncfusion:DropDownMenuGroup.ItemTemplate>

Names instead of CorrMarkets resolve


Marked as answer
Loader.
Up arrow icon