Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all 18858 articles
Browse latest View live

Dispose Usercontrol in itemsControl Wpf

$
0
0

Hi,

I have scenario where I am creating multiple times usercontrol.
<ItemsControl ItemsSource="{Binding ItmCollection, Mode=TwoWay}">
                <ItemsControl.ItemTemplate>
                    <DataTemplate>
                        <local:UserDefinedControl />
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
                <ItemsControl.ItemsPanel>
                    <ItemsPanelTemplate>
     <Grid local:GridHelpers.RowCount="{Binding RowCount,Mode=TwoWay}" local:GridHelpers.ColumnCount="{Binding ColumnCount, Mode=TwoWay}" />
                    </ItemsPanelTemplate>
                </ItemsControl.ItemsPanel>
                <ItemsControl.ItemContainerStyle>
                    <Style>
                      <Setter Property="Grid.Row" Value="{Binding Y_AXIS}" />
                      <Setter Property="Grid.Column" Value="{Binding X_AXIS}" />
                    </Style>
                </ItemsControl.ItemContainerStyle>
            </ItemsControl>

Usually, userdefinedcontrol (user control name) is created 10 times and take memory around 15 MB. And itemscontrol in tab item and i have 2 buttons i.e. 1st one to create UI ItmCollection(ItemsSource binding) and second button is destroying ItmCollection (ItemsSource binding).Now, model object collections are destroying properly through IDisposable but UI object space still same and every time keep on adding. If I see task manager keep increasing memory space. Although I tried with destructor and unloaded event but not impact on memory part. Basically memory leak issue is there. 

Please help to dispose UI objects.


UWP Application with RTF and Browser component

$
0
0

I am developing UWP  application with

one grid cell having rtf control and another grid cell browser component

rtf control should open file for editing, creating and modifying

I want to browse the internet  and copy paste images and text into rtf file

rtf file should have hyper link based navigation to different sections of the document.

please somebody help me how to go about it.

Does the uwp toolbox richeditbox control support the above functionality?

Show form on second monitor

$
0
0

I would like show my form on second monitor

I define 

public object Location { get; private set; }

            this.Left = Screen.AllScreens[Monitor].Bounds.Width;
            this.Top = Screen.AllScreens[Monitor].Bounds.Height;
            this.Location = Screen.AllScreens[Monitor].Bounds.Location;
            new System.Drawing.Point(Screen.AllScreens[Monitor].Bounds.Location.X,                    Screen.AllScreens[Monitor].Bounds.Location.Y);

But Form show on first monitor

I wanna know how to get searchbox for mtable in datagrid .... in WPF project...

how to hide the buttons print save or complete hide float AxAcroPDF c# please.

How to load resources embedded in a WPF executable from a unit test?

$
0
0

Is it possible to read string resources from an executable? If so, how?

I need to write a unit test that compares all of the string resources in a WPF application against a gold standard and then integrate that into the release build process. 


Richard Lewis Haggard

Not able to test the prism window in version 7.1

$
0
0
I can able test the prism window in version 6.3 but i cant able to test the wpf window in prism 7.1 can anyone know the solution for the problem. 
 
I used bootstrapper class to get the shell window in version 6.3(prism) but cannot able to test the window prism in version 7.1 

Windows 10 v1803 has broken word suggestions for WPF Textboxes

$
0
0

We have confirmed when using word suggestions in Windows 10 from either the Touch keyboard or the hardware keyboard suggestions, the TextInput event no longer fires as of v1803. It works fine in v1709.

The issue is that if you select a word suggestion, it visually appears on the screen but the TextBox itself does not think the text has changed within it. However, the caret positiondoes update. The next time you enter a character, all the text gets committed.

This is a problem for two reasons:

  1. If a user picks a suggestions and navigates away, there is no binding that fires that can be read to commit the data.
  2. If you're using the preview events (like PreviewTextInput) to filter inputs, the caret position and the text itself is out of sync after selecting a suggestion and this can cause out of bounds exceptions.

Definitely needs to be fixed in Windows! Any other suggestions?

(I also posted here: https://stackoverflow.com/questions/50707685/wpf-textbox-text-does-not-update-with-word-suggestions-with-windows-10-v1803)


ViewModel Provider

$
0
0
This is regarding MVVM where the model has a list of other models. In my VM I want to use a class to expose the corresponding list of ViewModel, i.e.

    public class ViewModelCollection<TViewModel, TModel> : ObservableCollection<TViewModel>
            where TViewModel : ViewModelBase
            where TModel : ModelBase



In order for this class to generate VMs I am trying to use a VM generator that has the following interface:

    public interface IViewModelGenerator {
        TViewModel GetViewModel<TViewModel>(ModelBase model, object o) where TViewModel : ViewModelBase;
    }



What I am struggling with is creating an actual implementation of that interface. I tried to do this various ways including the approach below for a VM called MyVM

    class MyViewModelGenerator : IViewModelGenerator   {
        public TViewModel GetViewModel<TViewModel>(ModelBase model, object o) where TViewModel : ViewModelBase  {
            ArgumentViewModel viewModel;

            MyViewModel viewModel = new ArgumentViewModel();
            viewModel.Model = (MyModel) model;
            return (ViewModelBase) viewModel; <== Compile Error
        }

    }

However, I am getting a compile error "Cannot implicitly convert type ViewModelBase to TViewModel. Why can't I convert that since I have the restriction "where TViewModel : ViewModelBase" (and MyViewModelBase is derived from ViewModelBase)? And how can I implement such a VM generator?


Binding Issues when using reflect?

$
0
0

Ok this is a little complex.

Without going into it too much, I'm reflecting over a class to collect it's fields and then adding each field into a class

    public class MBINField
    {
        public string Name { get; set; }
        public dynamic Value { get; set; }
        public string NMSType { get; set; }
    }

I'm then adding all of these to a collection, and binding that collection to a listview itemsource, from there i use a TemplateSelector to display a datatemplate based on the type of object that is stored.

Now my issue comes from when the Value of an MBINField is a class, for some reason I cannot bind to the properties of that class. It throws the follow error:

System.Windows.Data Error: 40 :
BindingExpression path error: 'Name' property not found on 'object' ''GcBaseBuildingPalette' (HashCode=1107452)'. 
BindingExpression:Path=Name; 
DataItem='GcBaseBuildingPalette' (HashCode=1107452); 
target element is 'TextBox' (Name=''); 
target property is 'Text' (type 'String')

System.Windows.Data Information: 20 : 
BindingExpression cannot retrieve value due to missing information. 
BindingExpression:Path=Name; DataItem='GcBaseBuildingPalette' (HashCode=1107452); 
target element is 'TextBox' (Name=''); 
target property is 'Text' (type 'String')

System.Windows.Data Information: 21 : 
BindingExpression cannot retrieve value from null data item. This could happen when binding is detached or when binding to a Nullable type that has no value. 
BindingExpression:Path=Name; 
DataItem='GcBaseBuildingPalette' (HashCode=1107452); 
target element is 'TextBox' (Name=''); 
target property is 'Text' (type 'String')

System.Windows.Data Information: 10 : 
Cannot retrieve value using the binding and no valid fallback value exists; 
using default instead.
BindingExpression:Path=Name; DataItem='GcBaseBuildingPalette' (HashCode=1107452); 
target element is 'TextBox' (Name=''); 
target property is 'Text' (type 'String')

Now, i can confirm through debug that GcBaseBuildingPalette does indeed have a property called Name, and that the datacontext is correct and have a valid GcBaseBuildingPalette object. In fact if i add a onclick event to the textbox and in code behind set the value, it works without an issue

TextBox tb = (sender as TextBox);
MBINField field = (tb.DataContext as MBINField);
libMBIN.Models.Structs.GcBaseBuildingPalette  c = field.Value as libMBIN.Models.Structs.GcBaseBuildingPalette;
tb.Text = c.Name;

this works without any issues, So i cannot for the life of me work out why it wont work, it's also possible of interest that adding a converter to this problem never gets called, breakpoints are never hit in either Convert or ConvertBack.

I'm hoping this is something that is easy to fix!


Ben Murray

UI Responsiveness

$
0
0

I am retrieving my data using EF Async methods, the calls getting the data seem quick.  However I return the data through my VM as ObservableCollection and then bind to my grids.

However during this time my entire UI is unresponsive, I can't even move it on the screen, until all the grids have been bound to their ObservableCollection.

My understanding is to use await/async for DB calls and Task.Run for Cpu operations?  However if I wrap my DB calls in Task.Run, essentially putting them on their own thread, my UI becomes responsive, though no data in them yet since the DB calls are still executing, but at least the UI can be used by the user for other things.

What exactly is the best way to speed up a UI responsiveness when using async/await methods?  Or is the DbContext.Local (which returns the observablecollection) what is slowing it down, not the the DBContext.LoadAsync?


nlm

Problem with SQL Server 2012 Express prerequisites

$
0
0

Hi all,
I am trying to make a setup file for my WPF Project using "Setup Project", But I get the following errors when trying to build the project:

ERROR: To enable 'Download prerequisites from the same location as my application' in the Prerequisites dialog box, you must download file 'SqlExpress2012\SQLEXPR32_x86_ENU.EXE' for item 'SQL Server 2012 Express' to your local machine. For more information, see http://go.microsoft.com/fwlink/?LinkId=616018.

ERROR: To enable 'Download prerequisites from the same location as my application' in the Prerequisites dialog box, you must download file 'SqlExpress2012\SQLEXPR_x64_ENU.EXE' for item 'SQL Server 2012 Express' to your local machine. For more information, see http://go.microsoft.com/fwlink/?LinkId=616018.

Although I've downloaded and moved these files to Packages folder, it still gets this error. (I had the same problem with .Net Framework 4.6.1 prerequisites , after moving downloaded files to to the Packages folder, problem was fixed)

Forums are having problems again

$
0
0
Forums are missing lots of stuff.  User info etc.  Please fix MS!!!

Lloyd Sheen

What is wrong with this ObjectDataProvider declaration?

$
0
0

I was attempting to create a small application to display both System.Windows.Media.Colors and System.Drawing.SystemColors using ObjectDataProvider to wrap the two data sources. Oddly, Colors works but SystemColors does not. This is confusing given that the two are both defined as public static Color xxx {get;}

Here's the XAML.

<Window x:Class="WpfColors.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:sys="clr-namespace:System;assembly=mscorlib"
        xmlns:d="clr-namespace:System.Drawing;assembly=System.Drawing"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="800" Width="1000"><Window.Resources><ObjectDataProvider 
            ObjectType="{x:Type sys:Type}"
            x:Key="colorsTypeOdp"
            MethodName="GetType" ><ObjectDataProvider.MethodParameters><sys:String>
                    System.Windows.Media.Colors, 
                    PresentationCore</sys:String></ObjectDataProvider.MethodParameters></ObjectDataProvider><ObjectDataProvider 
            ObjectInstance="{StaticResource colorsTypeOdp}" 
            MethodName="GetProperties" 
            x:Key="colorPropertiesOdp"></ObjectDataProvider><ObjectDataProvider 
            ObjectType="{x:Type sys:Type}"
            x:Key="colorsSystem"
            MethodName="GetType" ><ObjectDataProvider.MethodParameters><sys:String>
                    System.Drawing.SystemColors, 
                    System.Drawing</sys:String></ObjectDataProvider.MethodParameters></ObjectDataProvider><ObjectDataProvider 
            ObjectInstance="{StaticResource colorsSystem}" 
            MethodName="GetProperties" 
            x:Key="colorPropertiesSysColors"></ObjectDataProvider></Window.Resources><Grid><Grid.RowDefinitions><RowDefinition /><RowDefinition /></Grid.RowDefinitions><ListBox 
            Grid.Row="0"
            ItemsSource="{Binding Source={StaticResource colorPropertiesOdp}}"
            ScrollViewer.HorizontalScrollBarVisibility="Disabled"
            ScrollViewer.VerticalScrollBarVisibility="Auto" ><ListBox.ItemsPanel><ItemsPanelTemplate><WrapPanel /></ItemsPanelTemplate></ListBox.ItemsPanel><ListBox.ItemTemplate><DataTemplate><StackPanel Orientation="Vertical"><Rectangle Fill="{Binding Path=Name}" Stroke="Black" Margin="4" StrokeThickness="1" Height="50" Width="130"/><Label Content="{Binding Path=Name}" /></StackPanel></DataTemplate></ListBox.ItemTemplate></ListBox><ListBox 
            Grid.Row="1"
            ItemsSource="{Binding Source={StaticResource colorPropertiesSysColors}}"
            ScrollViewer.HorizontalScrollBarVisibility="Disabled"
            ScrollViewer.VerticalScrollBarVisibility="Auto" ><ListBox.ItemsPanel><ItemsPanelTemplate><WrapPanel /></ItemsPanelTemplate></ListBox.ItemsPanel><ListBox.ItemTemplate><DataTemplate><StackPanel Orientation="Vertical"><Rectangle Fill="{Binding Path=Name}" Stroke="Black" Margin="4" StrokeThickness="1" Height="50" Width="130"/><Label Content="{Binding Path=Name}" /></StackPanel></DataTemplate></ListBox.ItemTemplate></ListBox></Grid></Window>

At design time we something like this:

So, Colors is working during design time. Both a color and a name of the color are displayed. However, SystemColors is only making it halfway there. As you can see from the inserted image, the name of the color is available but the Rectangle.Fill is not working. Suggestions?


Richard Lewis Haggard

How to close a Button.ContextMenu programmatically?

$
0
0

Is it possible to programmatically close a Button.ContextMenu? The reason I ask is because I have a Navigation Tray item that displays a WPF Window upon click on the tray icon. My client wants the Window to hide when it loses focus and this works. On the WPF Window is a Button that has a built in ContextMenu. When the button is clicked the ContextMenu displays. When the user clicks on the desktop the WPF Window notices its loss of focus and is collapsed. The problem is, the ContextMenu is left still visible on the display after the WPF Window has been hidden. The Button.ContextMenu has an IsOpen property so I bound that to a property in the ViewModel and, upon hiding the Window, a false was written into that property. Surprisingly, this did not close the ContextMenu. Nada. Nothing. ContextMenu remained visible. I was pretty sure that the binding was correct but, just to be sure, I violated MVVM and wrote a false to the attribute directly from the View itself. Still no joy. I'm beginning to suspect that IsOpen doesn't respond to a false being written to it. Very puzzling. Is there some way to programmatically close a ContextMenu?

This is a slightly simplified definition of the button and its context menu.

<Button
    Height="25" Width="20"
    x:Name="btnTripleDot"
    Command="{Binding CmdTripleButton}" ><Button.Style><Style TargetType="{x:Type Button}"><Style.Triggers><EventTrigger RoutedEvent="Click"><EventTrigger.Actions><BeginStoryboard><Storyboard><BooleanAnimationUsingKeyFrames 
Storyboard.TargetProperty="ContextMenu.IsOpen"><DiscreteBooleanKeyFrame KeyTime="0:0:0" Value="True"/></BooleanAnimationUsingKeyFrames></Storyboard></BeginStoryboard></EventTrigger.Actions></EventTrigger></Style.Triggers></Style></Button.Style><Button.ContextMenu><ContextMenu><MenuItem Header="Add Account" Command="{Binding CmdAddAccount, Source={StaticResource ViewModel}}" /><Separator /><MenuItem Header="Help" Command="{Binding CmdHelp, Source={StaticResource ViewModel}}" /><MenuItem Header="PreVeil Website" Command="{Binding CmdPreVeilWebsite, Source={StaticResource ViewModel}}" /><Separator /><MenuItem Header="Quit" Command="{Binding CmdQuit, Source={StaticResource ViewModel}}" /></ContextMenu></Button.ContextMenu><Button.Template><ControlTemplate><Image Source="/KeyMenu;component/Resources/keymenu_more_32.png" /></ControlTemplate></Button.Template></Button>

Here's an example of the direct access to the IsOpen property being cleared.

protected override void OnDeactivated( EventArgs e )
{
    base.OnDeactivated( e );

    // TopRowV is the UserControl that contains the button.
    if (TopRowV != null)
        TopRowV.btnTripleDot.ContextMenu.IsOpen = false;

    // Call a function that hides the Window.
    Hide();
}


Richard Lewis Haggard


Could not load file or assembly Microsoft.Practices.Unity version=4.0.0.0 culture=neutral, PublicKeyToken=6d32ff45e0ccc69f

$
0
0
I've seen other posts with similar descriptions, but not exactly this one.  My app is a WPF MVVM with Prism, Unity and CommonServiceLocator.  Everything was fine until I decided to upgrade to the latest Prism and Unity versions. The NuGet version of Unity is v5.8.9.  Prism.Unity version is v6.3.0.  Prism.WPF version is v6.3.0.  Prism.Core version is v7.0.0.396.  And of course there are a slew of other assemblies installed via NuGet.  I suspect one of them must be referencing Microsoft.Practices.Unity v4.0.0.0, but I would not know how to verify that.

Rob E.

When to create a ViewModel in WPF

$
0
0

I'm coming from WinForms and I don't fully understand how things work in WPF MVVM architecture.

I'm trying to do a simple application that browses an excel file using an openFileDialog and then open the content of the excel file inside of a <g class="gr_ gr_15 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" data-gr-id="15" id="15">datagrid</g>. What <g class="gr_ gr_18 gr-alert gr_tiny gr_spell gr_inline_cards gr_run_anim ContextualSpelling multiReplace" data-gr-id="18" id="18">i</g> have at the moment is a FileViewModel Service which opens the openFileDialog because as far as I understand that the OpenfileDialog needs to be a service to fully aligned within the MVVM architecture.

One of my problem here is how to pass Models from a ViewModel to another ViewModel. Second, which bothers me most is when to create a <g class="gr_ gr_25 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" data-gr-id="25" id="25">viewModel</g> in MVVM. Do I need to create a View for every ViewModel? Let's take my example, I do have a ViewModel OpenFileDialog, do <g class="gr_ gr_29 gr-alert gr_tiny gr_spell gr_inline_cards gr_run_anim ContextualSpelling multiReplace" data-gr-id="29" id="29">i</g> need to create a userControl View name OpenFileDialogView then add that view to the MainWindow and then create another view for the DataGrid which displays the content of the excel file? If I want to add the functionality to create another Person using a Window, Do <g class="gr_ gr_11 gr-alert gr_tiny gr_spell gr_inline_cards gr_run_anim ContextualSpelling multiReplace" data-gr-id="11" id="11">i</g> need to add another View and another ViewModel?

public class FileModelService
{
	public object FileContent{get;set;}
	public void Open()
	{
		//Read the excel file
		FileContent=(PersonModel)ReadExcel(filename);	
	}
}

public class PersonModel
{
	public string Name{get;set;}
}

PS: I'm sorry about the added formatting styles. I don't really have an idea why it adds those text in my question.



WPF Form Design question

$
0
0

Hello All:

I am posting WPF question in this forum. Please let me know if it is not the right forum for this. I am working on a project with WPF. So far I was able to create new window. I did not work on my project for a week or so. And I cannot create new window now. It does not give me that option anymore. However If I create a new project, I am seeing that option. Could anyone please let me know how to fix the issue with my working project. I hate to create new project and copy all the code. Its too much.

Thanks,

Shwetha.

Can you help me about listwiew

$
0
0

I have picture and I want to add  Items like picture and text together with dynamically with code  

can you help me I don't know how to do it ?

Performance Issue with Row Number but Column Number Working Super Fast.

$
0
0

Performance Issue with Row Number but Column Number Working Super Fast.

       foreach (DataGridCellInfo obj in datagrid.SelectedCells)
            {
               var selectedcells = new SelectedCellsModel
                {
                RowNumber = datagrid.Items.IndexOf(obj.Item),
                ColumnName = obj.Column.SortMemberPath
                };

                updateVm.Collection.SelectedCells.Add(selectedcells);
            }

Viewing all 18858 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>