Build modern Windows desktop apps with WPF and MVVM. Learn XAML, binding, commands, templating, dependency properties, navigation, and async UI. Improve performance, accessibility, and testing for robust, maintainable projects.
1,319 posts332 contributors
This does not work. gLBxForecastCities.Items.Clear(); dlgForecast dlg = new dlgForecast(); WindowStartupLocation = WindowStartupLocation.CenterOwner; dlg.ShowDialog(); How do I open a dialog box that opens centered on the current dialog box?
In my new project, which I'm developing with WPF in .NET 10, I'm having trouble using the PasswordBox in a user authentication window. In my code, I've used the PasswordBox's KeyDown and PreviewKeyDown events. Normally, when a user enters their password and presses Enter, if the password is correct, DialogResult is set to true and the Close() method is called. And it's at this point that the program stops, when DialogResult is set to true. The program crashes without returning an error message. However, in a previous project I developed with WPF in .NET Framework, I didn't encounter this problem. Despite my research, I haven't found a solution. The good news is that when the validation button is clicked after entering the password, the window closes without any problem. Pressing Enter when the PasswordBox has focus causes a problem. Please, I need to understand how to fix this bug.
Hi everyone, I’m coming from a Windows Forms background where I used EDMX (Entity Data Model) to map my SQL Server database. I really liked how I could easily update the model from the database and get all the fields ready to use in my code whenever the DB structure changed. Now I’m moving to WPF, and I’d like to keep the same convenience — meaning, if I modify the database, I want to be able to update a data model (like EDMX) so that my entities and properties stay in sync automatically. I’d like to keep using Entity Framework and SQL Server, but I’m not sure what’s the best approach in WPF for this scenario. Any suggestions or modern alternatives to EDMX that would work well in WPF? Thanks in advance for your help!
Electron with .Net MVC application can be do like desktop application in .NET 9
Hi Team I have a rectangle and in between there is big space in between, want to minimize this space a bit by adjusting the margin of the grid so that it can be pushed a bit closer. How can i achieve such from this below code? <Grid Background="White" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Margin="0,29,0,10" Width="1766"> <Rectangle HorizontalAlignment="Left" Height="257" Stroke="#FFCFCFD1" VerticalAlignment="Top" Width="260" Margin="14,104,0,0"/> <!---Ingredient Totals--> <Rectangle HorizontalAlignment="Left" Height="257" Stroke="#FFCFCFD1" VerticalAlignment="Top" Width="260" Margin="290,104,0,0"/> <Label x:Name="lblMacros" FontWeight="SemiBold" Visibility="Visible" Content="Macros:" HorizontalAlignment="Left" VerticalAlignment="Top" Width="124" HorizontalContentAlignment="Right" Background="#FFE3E3E3" Margin="296,137,0,0" BorderThickness="1" BorderBrush="#FFBEBEBE" Height="23" FontSize="10"/> <TextBox x:Name="txtMacroTotal" FontSize="10" Foreground="Black" HorizontalAlignment="Left" Visibility="Visible" Height="20" Margin="425,138,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120"/> <Label x:Name="lblMacroTotal" FontSize="10" FontWeight="SemiBold" Visibility="Visible" Content="Totals:" HorizontalAlignment="Left" VerticalAlignment="Top" Width="125" HorizontalContentAlignment="Right" Background="#FFE3E3E3" Margin="296,163,0,0" BorderThickness="1" BorderBrush="#FFBEBEBE" Height="23"/> <TextBox x:Name="txtTotal" Foreground="Black" FontSize="10" HorizontalAlignment="Left" Visibility="Visible" Height="23" Margin="426,163,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="122"/> <!--GataGrid name on top--> <Label Content="Macros" FontWeight="SemiBold" HorizontalAlignment="Left" HorizontalContentAlignment="Center" VerticalAlignment="Top" Width="780" BorderB
C# WPF --- This is a "continuation" of c-sharpcorner.com/forums/what-is-a-simple-way-to-add-scrollbars-to-a-listbox. XAML <StackPanel Orientation="Vertical"> <ListBox x:Name="gLBxCharacters" Margin="5,0,5,0" ScrollViewer.HorizontalScrollBarVisibility="Visible" ScrollViewer.VerticalScrollBarVisibility="Visible" /> </StackPanel> This does not work. XAML <ListBox x:Name="gLBxCharacters" Margin="5,0,5,0" ScrollViewer.HorizontalScrollBarVisibility="Visible" ScrollViewer.VerticalScrollBarVisibility="Visible" /> This does work after < StackPanel ...> is removed.
C# WPF xaml: <ListBox x:Name="gLBxCharacters" Margin="5,0,5,0" ScrollViewer.VerticalScrollBarVisibility="Visible" /> This displays a scrollbar. But it does not scroll the contents of the ListBox. What is a simple way to add Scrollbars to a ListBox?
Hi, everyone and thanks in advance. I have a WPF DataGrid project using xmldataprovider to populate the datagrid. using a simple xml file - setlists.xml. In Window.Resources, If I set the source of the xml file to a folder such as d:\xml files\setlists.xml the datagrid populates perfectly. However, if I include the xml file in the project solution the datagrid won't populate. This works: <XmlDataProvider x:Name="AlanDb" x:Key="mysets" XPath="Details" Source="D:\xml files\setlists.xml"> This fails: <XmlDataProvider x:Name="AlanDb" x:Key="mysets" XPath="Details" Source= "setlists.xml"> Using Visual Studio 2022 Any suggestions would be appreciated. Thanks Alan
c-sharpcorner.com/forums/how-do-i-convert-a-list-element-to-text The response does not convert to an xaml text box. How do I convert a list element to text? ... Continued.
XAML <TextBox x:Name="gTBxComment" Background="#ffffcc" /> XAML.CS gTBxComment.Background = ??? How do I change the background of a TextBox to another color?
XAML <GroupBox Name="FirstGroupBox" Header="1st" Margin="10,0,5,0" Height="auto" Width="auto" > <RadioButton x:Name="gRBuResearcher1" Content ="Researcher" Click="gRBuResearcher1_Click" /> <RadioButton x:Name="gRBuScientist1" Content="Scientist" Click="gRBuScientist1_Click" /> <RadioButton x:Name="gRBuMedic1" Content="Medic" Click="gRBuMedic1_Click" /> </GroupBox> XAML.CS using System.Windows.Controls; foreach (var child in FirstGroupBox.Children) { if (child.Content is "Scientist") { RadioButton.IsChecked = true; } } This does not work. How do I set gRBuScientist1 to true?
c-sharpcorner.com/forums/how-do-i-uncheck-all-radio-buttons-at-one-time XAML <GroupBox Name="FirstGroupBox" Header="1st" Margin="10,0,5,0" Height="auto" Width="auto" > <RadioButton x:Name="gRBuResearcher1" Content ="Researcher" Click="gRBuResearcher1_Click" /> <RadioButton x:Name="gRBuScientist1" Content="Scientist" Click="gRBuScientist1_Click" /> <RadioButton x:Name="gRBuMedic1" Content="Medic" Click="gRBuMedic1_Click" /> </GroupBox> XAML.CS using System.Windows.Controls; foreach (var child in FirstGroupBox.Children) { if (child is RadioButton rb) { rb.IsChecked = false;// Uncheck each RadioButton } } results in error message "GroupBox does not contain a definition for 'Children' ...." => snipboard.io/9dnwLZ.jpg
I have two columns of Radio Buttons => snipboard.io/Xy3IQr.jpg. xaml <StackPanel Orientation="Vertical"> <RadioButton x:Name="gRBuResearcher1" Click="gRBuResearcher1_Click" > <Label Content="Researcher"/> </RadioButton> <RadioButton x:Name="gRBuScientist1" Click="gRBuScientist1_Click" > <Label Content="Scientist"/> </RadioButton> <RadioButton x:Name="gRBuMedic1" Click="gRBuMedic1_Click" > <Label Content="Medic"> </RadioButton> <RadioButton x:Name="gRBuDispatcher1" Click="gRBuDispatcher1_Click" > <Label Content="Dispatcher"/> </RadioButton> </StackPanel> ... <StackPanel Orientation="Vertical"> <RadioButton x:Name="gRBuResearcher3" Click="gRBuResearcher3_Click" > <Label Content="Researcher"/> </RadioButton> <RadioButton x:Name="gRBuScientist3" Click="gRBuScientist3_Click" > <Label Content="Scientist"/> </RadioButton> <RadioButton x:Name="gRBuMedic3" Click="gRBuMedic3_Click" > <Label Content="Medic"/> </RadioButton> <RadioButton x:Name="gRBuDispatcher3" Click="gRBuDispatcher3_Click" > <Label Content="Dispatcher"/> </RadioButton> </StackPanel> xaml.cs //------------------------------ private void gRBuResearcher1_Click(object sender, RoutedEventArgs e) { gstCharacter1 = "Researcher"; }//gRBuResearcher1_Click //------------------------------ //------------------------------ private void gRBuScientist1_Click(object sender, RoutedEventArgs e) { gstCharacter1 = "Scientist"; }//gRBuScientist1_Click //------------------------------ //------------------------------ private void gRBuMedic1_Click(object sender, RoutedEventArgs e) { gstCharacter1 = "Medic"; }//gRBuMe
Is there a way to uncheck all radio buttons at one time?
XAML <GroupBox Name="FirstGroupBox" Header="1st" Margin="10,0,5,0" Height="auto" Width="auto" > <RadioButton x:Name="gRBuResearcher1" Content ="Researcher" Click="gRBuResearcher1_Click" /> <RadioButton x:Name="gRBuScientist1" Content="Scientist" Click="gRBuScientist1_Click" /> <RadioButton x:Name="gRBuMedic1" Content="Medic" Click="gRBuMedic1_Click" /> </GroupBox> xaml.cs foreach (RadioButton rb in GroupBox:Name FirstGroupBox)) { } does not work. How do I retrieve every RadioButton in the GroupBox?
xaml: <TextBox x:Name="gTBxChar2"/> xaml.cs List<string> liststStringParsed = new List<string>(); liststStringParsed.Add("a"); liststStringParsed.Add("b"); liststStringParsed.Add("c"); gTBxChar2 = liststStringParsed[2]; "gTBxChar2 = liststStringParsed[2]" is not acceptable. How do I convert a list element to text?
WPF <StackPanel Orientation="Vertical" HorizontalAlignment="Center"> <RadioButton x:Name="gRBuArchivist" > </RadioButton> <Label Content="Archivist" /> </StackPanel> This code results in => snipboard.io/kYsolb.jpg. How do I center a label under a radio button?
Hi Team I need some help, have a combo box, it suppose when loading the application it loads the recipe codes name on the combo box, but its not but the data is on the grid fine. Maybe there is a property that is conflicting with this. Below is my logic <!---Stock code variable holder--> <UserControl.Resources> <CollectionViewSource x:Key="StockCode" Source="{Binding Code}"/> <CollectionViewSource x:Key="StockDescription" Source="{Binding Description}"/> </UserControl.Resources> <!---Recipe name and drop down box--> <Label x:Name="lblDriverName_Copy" FontWeight="SemiBold" Visibility="Visible" Content="Recipe Code:" HorizontalAlignment="Left" VerticalAlignment="Top" Width="179" HorizontalContentAlignment="Right" Background="#FFE3E3E3" Margin="17,65,0,0" BorderThickness="1" BorderBrush="#FFBEBEBE"/> <ComboBox x:Name="cbxRecipe" TabIndex="1" IsTextSearchEnabled="True" IsEditable="True" IsTextSearchCaseSensitive="False" Foreground="Black" HorizontalAlignment="Left" Margin="207,63,0,0" VerticalAlignment="Top" Width="214" SelectionChanged="cbxRecipe_SelectionChanged"> <ComboBox.ItemsPanel> <ItemsPanelTemplate> <VirtualizingStackPanel /> </ItemsPanelTemplate> </ComboBox.ItemsPanel> </ComboBox> <Label Content="Macros" FontWeight="SemiBold" HorizontalAlignment="Left" HorizontalContentAlignment="Center" VerticalAlignment="Top" Width="780" BorderBrush="#FFBEBEBE" Background="#FFE3E3E3" BorderThickness="1.5" Foreground="Black" Height="35" VerticalContentAlignment="Center" FontSize="14" Margin="14,498,0,0"/> <DataGrid x:Name="dgvMacroRecipe" VerticalScrollBarVisibility="Visible" SelectedCellsChanged="dgvMacroRecipe_SelectedCellsChanged" CellEditEnding="dgvMacroRecipe_CellEditEnding" VerticalAlignmen
Hi Team I want users when the form load(loads recipes product) fine, now i want this field to fill in a color will be fetched from the store procedure? How can achieve such in wpf? // front end <Label x:Name="lblColors" FontWeight="SemiBold" Visibility="Visible" Content="Colors:" HorizontalAlignment="Left" VerticalAlignment="Top" Width="179" HorizontalContentAlignment="Right" Background="#FFE3E3E3" Margin="17,142,0,-29" BorderThickness="1" BorderBrush="#FFBEBEBE"/> <TextBox x:Name="txtColor" IsEnabled="False" FontSize="10" Foreground="Black" HorizontalAlignment="Left" IsReadOnly="False" Visibility="Visible" Height="26" Margin="207,140,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="214" RenderTransformOrigin="1.19,-4.084"/>
Hi Team I have this front end fields and will share my code, basically need to find a way when the recipes loads. I need to find each product its specific color for that but it must be pulled from the database, i dont have the column for colors. Then i must be able to save these fields to the table. [dbo].[Adr_Batch_Suite].[Premix_Control], so that when i click Preview button, i can able to see these saved fields in this window, so far already this loads window pop up screen but not saving them need help on this. But the saved fields must be able to view on this form. Help me on my current logic. I will share back end first code, followed by front end. // Store procedure for dynamic queries //Managers class access the entities(uses store procedures these entities from the database) public static DataTable GetRecipeIngredients(int recipeID, string productAllocation, int NoPremix) { Managers.BatchMaterialManager.SetAdriotConnection(); return DataAccessProvider.GetDataTable(PremixBatch.PROC_NAME_GET, new object[] { "Calculate", null, null, recipeID, productAllocation, NoPremix }); } //Entities class uses store proc using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Feedmill_Weighbridge.Entities { public class PremixBatch { public const string PROC_NAME_GET = "[dbo].[spGetPremixBatch]"; // public const string PROC_NAME_STORE = "[quality].[spStorePellet]"; //string _Description; // string _BatchSize; //string _ProdCode; public PremixBatch() { } // int _IDX; //string _RecCode; string _RecDesc; string _ProdCode; int _TotalWeight; public string ProdCode { get { return _ProdCode; }