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

Is WPF the worst mistake in development technology Microsoft has ever made? Is WCF the best development technology Microsoft has ever made?

$
0
0

·        Clearly, my point of view is yes on both counts.

WPF is the worst, largest scale mistake in development technology Microsoft has ever made

WCF is the best development technology Microsoft has ever made

I believe that WPF shows a lack of integrity as it is a waste of time, money and effort for the development community and technology consumers world wide.  My reasoning is that Microsoft owns the desktop development platform there is no reason for a regression to a mark up language when the WYSIWYG forms platform was high productivity technology.  Mark up language development from Microsoft should have been left in the Web domain.  I personally have worked for 10 years on very large web sites hand coding mark up language - there was no need for this regression back to almost Mainframe like coding tools on the desktop platform which Microsoft owns.

I believe that this move was regressive, not in the best interests of Microsoft, nor the Microsoft developer community and certainly WPF was not a technology decision of integrity and has not brought productivity improvements for clients.

I would like to start a discussion on this and put it out there in the public domain for sensible and mature consideration by experienced developers with preferably 15+ years experience across multiple platforms and technologies.  My personal experience is 20 years starting on Unix C, then VB, Sybase, MSQL, Unix, ASP, ASP.NET, VB.NET, C#, Java, Winforms, WPF, AJAX, MTS, COM, DCOM, Web Services, WCF, SharePoint, BizTalk, Dynamics, MSCRM....

 


wpf RichTextBox text edit

$
0
0

Hello.

question1)

myFlowDoc.Blocks.Add(new Paragraph(new Run("Happy")));
myFlowDoc.Blocks.Add(new Paragraph(new Run("I am happy")));
myFlowDoc.Blocks.Add(new Paragraph(new Run("You")));

myFlowDoc.Blocks.Add(new Paragraph(new Run("I am happy")));  <-- "I am Always happy"

I want to edit. 

"Always" <- insert.

question2) How to get blocks index from event.

 Answers, please.





Trigger when vertical scrollbar thumb height is less than some value

$
0
0

I have custom scrollbar where thumb (moving part) has image in its center. I need to collapse image when thumb height is less than image height. It seems that there is no way to trigger on current height of thumb (i tried height and actualheight properties, both are wrong).

<local:CutoffConverter x:Key="ThumbHeightConverter" Cutoff="34" />

<Style x:Key="ScrollBarThumb" TargetType="{x:Type Thumb}">
        <Setter Property="SnapsToDevicePixels" Value="True" />
        <Setter Property="OverridesDefaultStyle" Value="True" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Thumb}">
                    <Border Name="ThumbBorder" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}">
                        <Border.Style>
                            <Style TargetType="{x:Type Border}">
                                <Setter Property="Background" Value="{StaticResource VScrollBarThumbNormalBrush}" />
                            </Style>
                        </Border.Style>
                        <Grid>
                            <Image Name="ThumbImage" Stretch="Fill" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" >
                                <Image.Style>
                                    <Style TargetType="{x:Type Image}">
                                        <Setter Property="Width" Value="26" />
                                        <Setter Property="Height" Value="34" />
                                        <Setter Property="MinHeight" Value="34" />
                                        <Setter Property="MaxHeight" Value="34" />
                                        <Setter Property="Source" Value="{StaticResource VScrollBarThumbNormal}" />
                                        <Style.Triggers>
                                            <DataTrigger Binding="{Binding Path=ActualHeight,
                                                RelativeSource={RelativeSource Mode=FindAncestor,
                                                AncestorType={x:Type Thumb}},
                                                Converter={StaticResource ThumbHeightConverter}}" Value="True">
                                                <Setter Property="Visibility" Value="Collapsed" />
                                            </DataTrigger>
                                        </Style.Triggers>
                                    </Style>
                                </Image.Style>
                            </Image>
                        </Grid>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter TargetName="ThumbImage" Property="Source" Value="{StaticResource VScrollBarThumbHover}" />
                            <Setter TargetName="ThumbBorder" Property="Background" Value="{StaticResource VScrollBarThumbHoverBrush}" />
                        </Trigger>
                        <Trigger Property="IsDragging" Value="True">
                            <Setter TargetName="ThumbImage" Property="Source" Value="{StaticResource VScrollBarThumbPressed}" />
                            <Setter TargetName="ThumbBorder" Property="Background" Value="{StaticResource VScrollBarThumbPressedBrush}" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>


Converter code:

    public class CutoffConverter : IValueConverter
    {
        public int Cutoff { get; set; }

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (!(value is double))
                return false;
            if (Double.IsNaN((double)value))
                return false;
            return ((int)((double)value)) < Cutoff;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }

Error in the i:EventTrigger, the local property "Actions" can only be applied to types that are derived from "System_Windows_Interactivity_TriggerBase_0_33413626".

$
0
0

I am getting the following error in the view:

SeverityCodeDescription ProjectFileLine
ErrorThe local property "Actions" can only be applied to types that are derived from "System_Windows_Interactivity_TriggerBase_0_33413626".


The view is as follow:

<Image    Margin="0" Width="{Binding nozzleLoadingImageBDWidth}" Height="{Binding nozzleLoadingImageBDHeight}" Source="/PressureVessels;component/images/NozzleLoadingSphere.PNG"><i:Interaction.Triggers><i:EventTrigger EventName="MouseLeftButtonDown"><light:EventToCommand Command="{Binding nozzleLoadingImageBD_MouseLeftButtonDownCmd}"/></i:EventTrigger></i:Interaction.Triggers></Image>

How to fix it? The command works fine and the application can run but the error is still there. Thanks a lot.

Not able to set focus to control in a user control

$
0
0

Hi,

I have a user control in which I have a datepicker control. The user control is set as a content in a content control and is visible on some button click.

Can anyone suggest how can I set focus to this datepicker control when this user control becomes visible? Right now the focus goes on to the Window.

I have already tried multiple things to set focus on Loaded,IsVisibleChanged event and so on and even tried doing FocusManager.FocusedElement={Binding DatePickerName}. I couldn't achieve any success on trying all this.


How to add progress bar into list box / custom progress bar

$
0
0

Problems:

How to add progress bar into list box as shown image / custom progress bar ?
The progress bar value increment represent the time elapsed (sec).



MainWindow.xaml

<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:wpf_ItemsControl_Wrapped"
        xmlns:sys="clr-namespace:System;assembly=mscorlib"
        x:Class="wpf_ItemsControl_Wrapped.MainWindow"
        mc:Ignorable="d" Title="MainWindow" Height="350" Width="525"><Grid><Grid.Resources><Style TargetType="{x:Type Button}"><Setter Property="Margin" Value="4"/></Style></Grid.Resources><Grid.RowDefinitions><RowDefinition Height="Auto" /><RowDefinition Height="Auto" /><RowDefinition Height="Auto" /><RowDefinition Height="*"/></Grid.RowDefinitions><Button HorizontalAlignment="Center" Content="Start" Command="{Binding StartCommand}" Width="80" Height="40" /><StackPanel Orientation="Horizontal" Grid.Row="1" Margin="4, 8, 4, 8"><TextBlock Text="Current Value:" VerticalAlignment="Center" /><!--TBC--><!--<TextBlock Text="x" VerticalAlignment="Center" />--></StackPanel><StackPanel Orientation="Horizontal" Grid.Row="2" Margin="4, 8, 4, 8"><TextBlock Text="Time Elapsed: " VerticalAlignment="Center" /><!--TBC--><!--<TextBlock Text="x" VerticalAlignment="Center" />--></StackPanel><ListBox Grid.Row="3" Grid.IsSharedSizeScope="True" AlternationCount="10000" ItemsSource="{Binding Models}" ScrollViewer.HorizontalScrollBarVisibility="Disabled"><ListBox.ItemContainerStyle><Style TargetType="{x:Type ListBoxItem}"><Setter Property="Template"><Setter.Value><ControlTemplate TargetType="{x:Type ListBoxItem}"><ContentPresenter/></ControlTemplate></Setter.Value></Setter></Style></ListBox.ItemContainerStyle><ListBox.ItemsPanel><ItemsPanelTemplate><WrapPanel Orientation="Horizontal" Margin="15, 0, 15, 0" /></ItemsPanelTemplate></ListBox.ItemsPanel><ListBox.ItemTemplate><DataTemplate><Grid><Grid.RowDefinitions><RowDefinition Height="Auto" /><RowDefinition Height="30" /></Grid.RowDefinitions><Grid.ColumnDefinitions><ColumnDefinition MinWidth="120" SharedSizeGroup="AllSameWidth" /></Grid.ColumnDefinitions><Grid><local:ItemTracer HorizontalAlignment="Stretch" Container="{Binding ., RelativeSource={RelativeSource AncestorType={x:Type WrapPanel}}}" ContainerWidth="{Binding ActualWidth, RelativeSource={RelativeSource AncestorType={x:Type WrapPanel}}}" ItemIndex="{Binding (ItemsControl.AlternationIndex), RelativeSource={RelativeSource AncestorType={x:Type ListBoxItem}}}" ItemsCount="{Binding Items.Count, RelativeSource={RelativeSource AncestorType={x:Type ListBox}}}" x:Name="lastInLine" /><Border BorderThickness="1" BorderBrush="Gray" x:Name="border" Height="30"><Border.Style><Style TargetType="{x:Type Border}"><Style.Triggers><DataTrigger Binding="{Binding (ItemsControl.AlternationIndex), RelativeSource={RelativeSource AncestorType={x:Type ListBoxItem}}}" Value="0"><Setter Property="CornerRadius" Value="10, 0, 0, 10" /></DataTrigger><DataTrigger Binding="{Binding IsLastItem, ElementName=lastInLine}"
												Value="true"  ><Setter Property="CornerRadius" Value="0, 10, 10, 0" /></DataTrigger><DataTrigger Binding="{Binding Items.Count, RelativeSource={RelativeSource AncestorType={x:Type ListBox}}}" Value="1"><Setter Property="CornerRadius" Value="10, 10, 10, 10" /></DataTrigger></Style.Triggers></Style></Border.Style><TextBlock Text="{Binding CurrentValue}" VerticalAlignment="Center" HorizontalAlignment="Center" /></Border></Grid><TextBlock Text="{Binding StartTime, StringFormat=\{0:mm\\:ss\}}" Grid.Row="1" Margin="-14, 0, 0, 0" /><TextBlock Text="{Binding EndTime, StringFormat=\{0:mm\\:ss\}}"  Grid.Row="1" HorizontalAlignment="Right"><TextBlock.RenderTransform><TranslateTransform X="14" Y="0" /></TextBlock.RenderTransform><TextBlock.Style><Style TargetType="{x:Type TextBlock}"><Setter Property="Visibility" Value="Visible"/><Style.Triggers><MultiDataTrigger><MultiDataTrigger.Conditions><Condition Binding="{Binding IsLastInLine, ElementName=lastInLine}" Value="False" /><Condition Binding="{Binding IsLastItem, ElementName=lastInLine}" Value="False" /></MultiDataTrigger.Conditions><Setter Property="Visibility" Value="Collapsed" /></MultiDataTrigger></Style.Triggers></Style></TextBlock.Style></TextBlock></Grid></DataTemplate></ListBox.ItemTemplate></ListBox></Grid></Window>

MainWindowViewModel.cs

using System;
using System.Collections.ObjectModel;
using System.Linq;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.CommandWpf;

namespace wpf_ItemsControl_Wrapped
{
    public class MainWindowViewModel : ViewModelBase
    {
        private ObservableCollection<Model> models;

        public ObservableCollection<Model> Models
        {
            get
            {
                if (models == null)
                {
                    models = new ObservableCollection<Model>();
                }
                return models;
            }
        }

        private ObservableCollection<Duration> durations;

        public ObservableCollection<Duration> Durations
        {
            get
            {
                if (durations == null)
                {
                    durations = new ObservableCollection<Duration>();
                }
                return durations;
            }
        }

        private RelayCommand _startCommand;

        public RelayCommand StartCommand
        {
            get
            {
                return _startCommand ?? (_startCommand = new RelayCommand(() =>
                {
                    //tbc
                    //increase progress bar value to indicate time elapsed (use timer to simulate)
                    // get current value text from the border (based on current elapsed time)
                }));
            }
        }

        private TimeSpan stepTime = TimeSpan.FromSeconds(15);

        public TimeSpan StepTime
        {
            get { return stepTime; }
            set
            {
                stepTime = value;
                RaisePropertyChanged();
            }
        }

        public MainWindowViewModel()
        {
            Models.Add(new Model { StartTime = LastEnd(), Duration = TimeSpan.FromSeconds(10), CurrentValue = new Random().Next() });
            Models.Add(new Model { StartTime = LastEnd(), Duration = TimeSpan.FromSeconds(20), CurrentValue = new Random().Next() });
            Models.Add(new Model { StartTime = LastEnd(), Duration = TimeSpan.FromSeconds(30), CurrentValue = new Random().Next() });
            Models.Add(new Model { StartTime = LastEnd(), Duration = TimeSpan.FromSeconds(40), CurrentValue = new Random().Next() });
            Models.Add(new Model { StartTime = LastEnd(), Duration = TimeSpan.FromSeconds(50), CurrentValue = new Random().Next() });
            Models.Add(new Model { StartTime = LastEnd(), Duration = TimeSpan.FromSeconds(60), CurrentValue = new Random().Next() });
        }

        public TimeSpan LastEnd()
        {
            return (Models.Count == 0) ? TimeSpan.FromSeconds(0) : Models.Last<Model>().EndTime;
        }
    }
}

Download Project (Credited to Andy ONeill)






Binding to Object Errors

$
0
0

Hey, im trying to bind to an instance of a class which I have created however there are errors with the binding. 

System.Windows.Data Error: 40 : BindingExpression path error: 'registerObject' property not found on 'object' ''LoginViewModel' (HashCode=25308009)'. BindingExpression:Path=registerObject; DataItem='LoginViewModel' (HashCode=25308009); target element is 'StackPanel' (Name=''); target property is 'DataContext' (type 'Object')


Below is the XAML where the errors are occurring, im simply trying to set the DataContext to my Class Instance so I can then Bind to it's properties. 

<StackPanel DataContext="{Binding registerObject}"><WrapPanel><TextBox Name="RegName" Tag="Full Name..." Text="{Binding FirstName}" />

Here is my ViewModel code which i'm trying to bind to, knowing my luck it's made some silly spelling mistake or some other stupid mistake!

namespace PhotoManagement
{
    public class LoginViewModel
    {
        //Initilize Form Objects
        Register registerObject = new Register();
        Login loginObject = new Login();
    }

    public class Register : NotifyUIBase
    {
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public string Email { get; set; }
        public string ClearPassword { get; set; }
        public string Salt { get; set; }
        public DateTime DateCreated { get; set; }
        public string Address { get; set; }

        public bool Result { get; set; }

        public RelayCommand RegisterCommand { get; set; }
        public Register()
        {
            FirstName = "Martyn";
            RegisterCommand = new RelayCommand(RegisterExecute);
        }
        private void RegisterExecute()
        {
            Salt = Common.Security.KeyGenerator.GetUniqueKey(64);
            Result = false;

            using (var db = new PhotoManagmentContext())
            {
                //Add account details
                var user = new User
                {
                    FName = FirstName,
                    LName = LastName,
                    Email = Email,
                    Hash = Common.Security.HashGenerator.CalculateHash(ClearPassword, Salt),
                    Salt = Salt,
                    DateCreated = DateCreated,
                    DateLastAccessed = DateCreated,
                    Address = Address,
                    Role = 0
                };

                db.Users.Add(user);
                try
                {
                    db.SaveChanges();
                    Result = true;
                }
                catch(Exception e)
                {
                    MessageBox.Show("There was an error updating database!");
                }
            }
        }
    }


Entity Framework MVVM, Insert Data into Database

$
0
0

This question is mainly aimed for Andy ONeill, as i'm basing my code on his guide. 

I have read and understood your code best I can. From what I can tell when fetching data to display:

  1. First of all create a ProductVM, this creates an instance of the Product Class and sets up the metadata for validation ect.
  2. Then each ProductVM is added to an ObservableCollection which is binded to. 

This makes sense, however I want to Insert some data, you have the starting for that but seems you never finished it, could you tell me if i'm wrong here:

  1. Bind to a list of commands, these CommandMessages are sent to the CrudVMBase where the method is defined.
  2. In this case InsertNew() is used, this method then initializes a new ProductVM.
  3. This then gets passed to EditVM which passes the Product Class instance to editEntity within CrudVMBase.

This is where i'm getting kind of lost, could you explain a bit more on where it goes from there. 

Also, how would I go about putting my data in an instance (in my case) user class? I originally binded to some properties in an instance of a class, however i'm not sure this is the correct way now. Some of the properties are filled in using code, not the user. 

Of course I would have to send the password using the command parameter as well as you can't bind to it. Below is the code I currently have, but I believe this is wrong.

public class Register : NotifyUIBase
    {

        public string ClearPassword { get; set; }
        public string Salt { get; set; } //Auto - Generated using code
        public DateTime DateCreated { get; set; } //Auto - Todays date
        public Visibility Result { get; set; } //Auto - Changed if there are no errors

        public RelayCommand RegisterCommand { get; set; }
        public Register()
        {
            Result = Visibility.Hidden;
            RegisterCommand = new RelayCommand(RegisterExecute);
        }
        private void RegisterExecute()
        {
            Salt = Common.Security.KeyGenerator.GetUniqueKey(64);
            DateCreated = DateTime.Now;

        }
    }

Edit:

Looking more into the code I see that the Commands you define on MainWindowViewModel are pretty vital in their setup. Due to my Views having many different Buttons which will need different commands, and not always being Menu Bar style, how could I setup a button on it's own without using a List? Could I just do the following and have the button Bind to it?

public CommandVM RegisterCommandButton { get; set; } = new CommandVM { CommandDisplay = "Register", IconGeometry = App.Current.Resources["InsertIcon"] as Geometry, Message = new CommandMessage { Command = CommandType.Insert } };


WPF Datagrid with different tooltip for each row/column

$
0
0

Hi, i have a WPF datagrid binded to a DataTable. Now i want to put different tooltips for every cell of the datagrid, how can i do this without binding the datagrid to another object (it is already binded to a DataTable).

Thanks in advance.

wpf listbox change items

$
0
0

Hello,
I need advice. I have two listboxes. In the first listbox I put my movies from the Webthemoviedb.org which collects information about the movie such as movie title, genre, and also whether the movie is added in a favorite playlist based on the check ToggleButton. And my question is how can I change from the second ListBox check togglebutton first ListBox with the film. Thanks a lot 

Source code : MoviePlexDemo

WPF MVVM - Master detail entry form with editable detail datagrid.

$
0
0
I have data entry form bound to viewmodel. I follow EF code-first approach and the details tables are represented by observable collections in my models, like below.

   
 public partial class item
    {
        public item()
        {
            orders = new ObservableCollection<order>();
        }
    }



Everything works fine but in few cases I have a master entry with a detail in the form of grid. Here's xaml part which binds SelectedItem.Orders to detail grid.

    
<UserControl x:Class="ABCD.Views.itemView"
        ....
        DataContext="{Binding itemMaster, Source={StaticResource Locator}}"
        Height="Auto" Width="Auto"><Grid><Grid.ColumnDefinitions.... /><Grid.RowDefinitions..../><DataGrid AutoGenerateColumns="False" VerticalAlignment="Top" ItemsSource="{Binding items}" SelectedItem="{Binding SelectedItem}" Name="dgitems" HorizontalAlignment="Stretch" RowDetailsVisibilityMode="VisibleWhenSelected" ><DataGrid.Columns><DataGridTextColumn x:Name="ItemNameColumn" Binding="{Binding Path=ItemName}" Header="Item Name" Width="125" /><DataGridTextColumn x:Name="ItemCodeColumn" Binding="{Binding Path=ItemCode}" Header="Item Code" Width="75" /><DataGridTextColumn x:Name="StockColumn" Binding="{Binding Path=StockLevel}" Header="Stock" Width="60" /></DataGrid.Columns></DataGrid><Label Grid.Column="3" Grid.Row="0" Margin="3,3,3,3" Content="Item Code"      VerticalAlignment="Center" /><TextBox Grid.Column="4" Grid.Row="0" HorizontalAlignment="Left" Margin="3,3,3,3" Name="ctrlItemCode" Text="{Binding Path=SelectedItem.ItemCode, Mode=TwoWay, ValidatesOnExceptions=true, NotifyOnValidationError=true}" Width="120" Height="Auto" VerticalContentAlignment="Center" /><Label Grid.Column="3" Grid.Row="2" Margin="3,3,3,3" Content="Product Name" VerticalAlignment="Center" /><TextBox Grid.Column="4" Grid.Row="2" HorizontalAlignment="Left" Margin="3,3,3,3" Name="ctrlProductName" Text="{Binding Path=SelectedItem.ItemName, Mode=TwoWay, ValidatesOnExceptions=true, NotifyOnValidationError=true}" Width="120" Height="Auto" VerticalContentAlignment="Center" /><DataGrid Grid.Column="2" Grid.Row="16" Grid.ColumnSpan="3"  Height="145" AutoGenerateColumns="False" VerticalAlignment="Top" ItemsSource="{Binding SelectedItem.Orders}"  Name="dgOrders" HorizontalAlignment="Stretch" ><DataGrid.Columns><DataGridTemplateColumn Width="120"><DataGridTemplateColumn.CellTemplate><DataTemplate><ComboBox DisplayMemberPath="OrderNumber" SelectedValuePath="OrderId"  ItemsSource="{Binding Path=DataContext.Orders,   RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}" SelectedValue="{Binding Path=OrderId}" /></DataTemplate></DataGridTemplateColumn.CellTemplate></DataGridTemplateColumn><DataGridTextColumn x:Name="QtyColumn" Binding="{Binding Path=Quantity}" Header="Qty" Width="75" /><DataGridTextColumn x:Name="PriceColumn" Binding="{Binding Path=Price}" Header="Price" Width="75" /><DataGridTextColumn x:Name="TotalColumn" Binding="{Binding Path=Total}" Header="Total" Width="75" /></DataGrid.Columns></DataGrid></Grid></UserControl>



In such cases, I want to calculate the total as soon as the user types price and quantity in the grid. I know it can be handled if we have related property in viewmodel. But in my case, the Orders is a collection in item model.

Thanks in advance.
                        

WPF + C#

$
0
0

I`m searching for good video courses to learn WPF + C#. the ones that include real world projects and not just theory about controls and concepts, etc... 

Does anyone knows where I can find or buy those?

Thanks.

table of .mdf database file didn't display inserted or modified record

$
0
0

Hi All.

I add Service-based Database ABC.MDF file and connect it to project. In database I created table and stored procedures. And base on it create table adapters in dataset and bidden form to it. The form can modify and add new record. But when add new record to the table or modify existing record ListView control display them. But when I open table I didn't see new record or modification of existing records. What is a problem? How to fix it?

Thanks.




Organizing Items and subitems in ObservableCollection

$
0
0

Hello everyone!

I am wondering how could I organize something like that:

Storage 1
      Cabinet 1
           Shelf 1
               Box 1
               Box 2
               Box 3
      Cabinet 2
           Shelf 2
               Box 4
               Box 5
      Cabinet 3
           Shelf 3
               Box 6
               Box 7
               Box 8
               Box 9

           Shelf 4
               Box 10
               Box 11
               Box 12
               Box 13

(I hope my English is correct and you can understand what I mean).
In my database I already configured to register every part(storage room, cabinet, shelf and box). Visually I would like to arrange that simulating the real stuff.
I tried to organize that in a observable collection, but I didn't know how to put the cabinets inside the room and etc.

The idead was create a tab for the storage, inside this tab, create another container for the cabinet, inside the cabinet create the boxes. Finally populate the boxes with items.
I could get the storage rooms in the tabcontrol, but how could I create a listbox for example, inside the tabitem as it`s child?

How can I do something like that?


Valdirnm




WPF ControlTemplate

$
0
0

hi can any one tell me in a nutshel, the spicific use of the <ContentPresenter> in a template... because i have tried to use it,,, but in my spicifically drawn templates, i usually get an error saying the content property is set more than once.

so i want to know the spicific use of the <ContentPresenter> in a templates cz i see it everywhere.


getting the sender from Addhandler WPF VB

$
0
0

WPF related:

Another question... (This is a problem i come accoss VERY often, but i usually try to work around it)

i have a loop lets say:

dim MyStack as new stackpanel
MyStack.orientation = orientation.Vertical

for each Filestring as string in system.io.directories.getDirectories("C:\", "*.*" , TopDirectories)
dim MyButton as new button
MyButton.Content = Filestring.remove(0,(Filestring.lastIndexOf("\")+1))'That is the get ONLY the name of the folder.
A
ddHandler Mybutton.Click,AddressOf MyButtonClick
'
MystackPanel.Children.Add(MyButton)

 Next

and then:

Private Sub MybuttonClick()

//''Do some stuff
End Sub

My question is, that im NOT allowed to link an address with values in like the sender or event args, i.e i cant link this:
Private Sub MyButtonClick (Byval sender as Object, Byval e as System.Windows.RoutedEventArgs)
End Sub

VB wil Give me a big error... now thats fine and dandy,,,, but my question is if im not allowed to send the sender, will will i be able to use the SENDER as button in the event i addressed, because its not publically declared, so i cant use it that way.

is it possible to send the button to the event as sender in able to use it  or not?

wpf RichTextBox get currnet line

$
0
0

I would like to know the current line  through this event.


myFlowDoc.Blocks.Add(new Paragraph(new Run("Happy")));
 myFlowDoc.Blocks.Add(new Paragraph(new Run("I am happy")));
 myFlowDoc.Blocks.Add(new Paragraph(new Run("You")));

myFlowDoc.Blocks.Add(new Paragraph(new Run("I am happy"))); <-richtextbox text click.  //

richtextbox.document = myFlowDoc;

get line is 1.  I want to current line.

privatevoid richtextbox_PreviewMouseLeftButtonUp(object sender,MouseButtonEventArgs e)
{
     
// get Current Line
 
}

thank you

Limit Lifetime of DbContext

$
0
0

How do I limit the lifetime of DbContext in a Prism Unity, EF6, WPF, Mvvm desktop app?  I did not see an example in the Prism 5 documentation.  This lifetimemanager documentation https://msdn.microsoft.com/en-us/library/microsoft.practices.unity.lifetimemanager.aspx may be deprecated.  But when I register my EntityUnitofWork class, I would like the Unity Container automatically dispose of EntityUnitOfWork after a view is deactivated in a region.

So this is how the view is registered and activated from the MenuViewModel:

RegionManager.RegisterViewWithRegion(RegionNames.MainRegionLeft, typeof(AdrTypeView));
Then in the AdrTypeViewModel  I create a new instance of DbContext, along with repositories in an EntityUnitofWork, like this:
using (CallingCreateUoWASync())
{
RegionManager.RegisterViewWithRegion(RegionNames.MainRegionLeft, typeof(AdrTypeView));
}

and this:

private async Task CallingCreateUoWASync()
    {
     await Task.Run(() =>
     {
         EntityUnitOfWork MyUnitOfWork = new EntityUnitOfWork();

     });
    }
Why I am doing it asynchronously is not relevant to the question, but the reason is for speed.  The unit of work not only creates DbContext, but also about 20 respositories that include various queries available to be run.  That takes about 4-5 seconds, which may seem like a long wait for some users.  So the UoW gets created async while the view is also being created.

When I activate another view, I still see the old values in the EntityUnitOfWork.  I want to dispose of the old EntityUnitOfWork.  How can I do that programmatically or configure it automatically with the Unity Container?  Thank you.

Canvas child controls zoom/position issue with inverse transform

$
0
0

Hello all,

In my application, i am using a canvas control which has a collection of ViewModel binded to it. This collection (Elements) has different type of UI controls. For each UI control a datatemplate is defined in the Resources as shown below.

<DataTemplate  DataType="{x:Type local:RectangleViewModel}"><Grid LayoutTransform="{Binding LayoutTransform.Inverse, RelativeSource={RelativeSource AncestorType=Canvas}}" x:Name="DoNotZoom" ><Rectangle Stroke="Red"></Rectangle></Grid></DataTemplate><DataTemplate  DataType="{x:Type local:EllipseViewModel}"><Grid x:Name="ZoomWithCanvas" ><Ellipse Stroke="Yellow" ></Ellipse></Grid></DataTemplate>

In the above DataTemplate, 'RectangleViewModel' is using 'LayoutTransform.Inverse which is not allowing this UI to get zoomed when Canvas is zoomed. 

Now i don't want the UI to be zoomed when Canvas gets zoomed. Here is the canvas code what i am using. 

<ScrollViewer x:Name="DesignerScrollViewer"
                        HorizontalScrollBarVisibility="Auto"
                        VerticalScrollBarVisibility="Auto" CanContentScroll="True"><ItemsControl  Grid.Column="2" ItemsSource="{Binding Elements}" ><ItemsControl.Style><Style><Setter Property="Canvas.Left" Value="0" /><Setter Property="Canvas.Top" Value="0" /></Style></ItemsControl.Style><ItemsControl.ItemsPanel><ItemsPanelTemplate><Canvas Loaded="Canvas_Loaded" x:Name="canvas"  Margin="2"></Canvas></ItemsPanelTemplate></ItemsControl.ItemsPanel></ItemsControl></ScrollViewer>

But with this code actually, the UI control is not getting zoomed but its position is not getting shifted in canvas when i am zooming the canvas control. How i can make sure that control is not zoomed but its shown at correct place inside the canvas. Whats wrong with the above code?

Thanks in advance,

IamHuM


Alternative to MediaElement ?

$
0
0
I want to play video in my app, but the MediaElement does not work ( that is, the sound is smooth, but the video is choppy ).  I've tried to ask for help here, but not got any replies, and I've also tried looking for alternatives, both by downloading the WPFMediaKit ( it blows up with a COM error trying to create a DirectShow object that I'm sure I had, and that I went and downloaded again, I also downloaded .NET 3.5 SP1 and found I had that, too ), and by trying to reuse a control that wraps windows media player.  However, while I can find no code difference between the two projects, in my new project, it plays audio and not video, the screen is blank.  I've tried running the new app from the same folder as the old one, in case it's a difference in a dependancy.  Basically, I've tried all I can think of, and I'd love to find another wrapper for the Windows Media Player that works cleanly, doesn't have strange dependancies to track down/redistribute, works all the time, and plays video smoothly.  It seems odd to me that WPF is a multi media platform and it doesn't have a reliable video player in it.

Any help recieved with much gratitude.

Christian Graus
Viewing all 18858 articles
Browse latest View live


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