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

How do I capture an object in real life in 3D and display it onto Paint 3D?

$
0
0
How do I capture a 3D object In 3D to use in Paint 3D?

Missing TouchUpEvent on RepeatButton

$
0
0

I have a WPF application such that there is a modal Window with a RepeatButton. When a limit is reached, a Dialog Window is displayed. Using the keyboard, mouse, or Stylus this works as expected. However when touch is used to change the value via the RepeatButton that results in the Dialog Window, after closing the Dialog Window, any touch of the application causes a Click event on the RepeatButton. In delving into the problem, I can see that a TouchUp event never occurs, likely interrupted by the Dialog Window.  In the Dialog Window I handle TouchUp and TouchDown, but even if I do not set e.Handled = true, the error occurs.

Note:  It does not matter if touch is used for the Dialog Window.  The problem occurs when touch is used on the RepeatButton. 

Does anyone have any ideas on how to solve this issue?




How to integrate Skype Business in a WPF application

$
0
0

Dear all,

We have an existing WPF application runing on Windows 10 for which a customer ask us to integrate Skype business as part of the application itselve.

Does anyone have already experiment such integration ?

regards

WPF application message box

$
0
0

I've a WPF application(A) deployed on to a Windows app server and hosted in IIS. I programmatically access this application from another WPF thick client application(B).

When the app A is launched from B,following message box(titled "Launching Application") comes up:

Verifying application requirements...this may take a few moments...

Is there any way at all to get rid of this message box completely please?

Thanks.

Switching between two controls in ContentControl

$
0
0

Hello, currently I am trying to build an application which has a ContentControl which switches between a derived DataGrid and a ListBox to provide two different views on Data:

<ContentControl Content="{Binding ElevationsView}" x:Name="ElevationsContentControl"><ContentControl.Resources><DataTemplate x:Key="ElevationsDetailedList"><local:ExtendedDataGrid ItemsSource="{Binding}" ScrollViewer.ScrollChanged="ElevationsDetailedList_ScrollChanged" AutoGenerateColumns="True" /></DataTemplate><DataTemplate x:Key="ElevationsTileView"><ListBox ItemsSource="{Binding}" ScrollViewer.ScrollChanged="ListBox_ScrollChanged" /></DataTemplate></ContentControl.Resources><ContentControl.Style><Style TargetType="{x:Type ContentControl}"><Style.Triggers><DataTrigger Binding="{Binding ViewMode}" Value="{x:Static local:ViewMode.DetailedList}"><Setter Property="ContentTemplate" Value="{StaticResource ElevationsDetailedList}" /></DataTrigger></Style.Triggers><Setter Property="ContentTemplate" Value="{StaticResource ElevationsTileView}" /></Style></ContentControl.Style></ContentControl>

The ExtendedDataGrid is at the moment only a derived class from DataGrid without any additional functionality. But if I start the application and the initial ViewMode is "DetailedList", I get the error "An object of Type "ExtendedDataGrid" cannot be converted into the type "System.Windows.Controls.ListBox".

It works, if I delete the ScrollChanged Event from either the ExtendedDataGrid or the ListView, or when I change the ExtendedDataGrid to DataGrid. But both aren't acceptable solutions for me, as I need the ExtendedDataGrid and the ScrollChanged event.

Does somebody knows the cause of this or can give me a workaround?

Custom paginable observablecollection

$
0
0
Hi! I found this code to paginate a collection. It works perfectly for what I need, but I would like to be able to paginate in another thread, since if the number of items per page is large, the interface freezes for a moment.

The "RecalculateThePageItems" method is responsible for creating each page (when the collection is created, when a record is deleted, when the page is changed). Some help? Thank you very much! 

using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;

namespace WPF.Utilidades
{
    /// <summary>
    /// This class represents a single Page collection, but have the entire items available inside
    /// </summary>

    public class PaginatedObservableCollection<T> : ObservableCollection<T>
    {
        #region Properties

        private const int FistPage = 1;

        private readonly List<T> _originalCollection;

        #region Commands

        public void ExecuteNextPage()
        {
            CurrentPage++;
            OnPropertyChanged(new PropertyChangedEventArgs("ItemsFrom"));
            OnPropertyChanged(new PropertyChangedEventArgs("ItemsTo"));
        }

        public bool CanExecuteNextPage()
        {
            return TotalPages > CurrentPage;
        }

        public void ExecutePreviousPage()
        {
            CurrentPage--;
            OnPropertyChanged(new PropertyChangedEventArgs("ItemsFrom"));
            OnPropertyChanged(new PropertyChangedEventArgs("ItemsTo"));
        }

        public bool CanExecutePreviousPage()
        {
            return CurrentPage > FistPage;
        }

        public void ExecuteFirstPage()
        {
            CurrentPage = FistPage;
            OnPropertyChanged(new PropertyChangedEventArgs("ItemsFrom"));
            OnPropertyChanged(new PropertyChangedEventArgs("ItemsTo"));
        }

        public bool CanExecuteFirstPage()
        {
            return TotalPages > 0 && CurrentPage != FistPage;
        }

        public void ExecuteLastPage()
        {
            CurrentPage = TotalPages;
            OnPropertyChanged(new PropertyChangedEventArgs("ItemsFrom"));
            OnPropertyChanged(new PropertyChangedEventArgs("ItemsTo"));
        }

        public bool CanExecuteLastPage()
        {
            return CurrentPage != TotalPages;
        }

        #endregion

        private int _itemsPerPage;

        private int ItemsPerPage
        {
            get { return _itemsPerPage; }
            set
            {
                if (value > 0)
                {
                    _itemsPerPage = value;
                    RecalculateItemsPerPage();
                    OnPropertyChanged(new PropertyChangedEventArgs("ItemsPerPage"));
                }
            }
        }

        private int _currentPage;

        public int CurrentPage
        {
            get { return _currentPage; }
            set
            {
                if (value > 0)
                {
                    _currentPage = value;
                    RecalculateItemsPerPage();
                    OnPropertyChanged(new PropertyChangedEventArgs("CurrentPage"));
                }
            }
        }

        private int _totalPages;

        public int TotalPages
        {
            get { return _totalPages; }
            set
            {
                if (_totalPages != value)
                {
                    if (value < _currentPage)
                    {
                        CurrentPage--;
                    }
                    _totalPages = value;
                    OnPropertyChanged(new PropertyChangedEventArgs("TotalPages"));
                }
            }
        }

        private int _totalItems;

        public int TotalItems
        {
            get { return _originalCollection.Count; }
            set
            {
                if (_totalItems != value)
                {
                    _totalItems = value;
                    OnPropertyChanged(new PropertyChangedEventArgs("TotalItems"));
                }
            }
        }

        private int _itemsFrom;

        public int ItemsFrom
        {
            get { return _originalCollection.Count > 0 ? (CurrentPage - 1) * ItemsPerPage + 1 : 0; }
            set
            {
                if (_itemsFrom != value)
                {
                    _itemsFrom = value;
                    OnPropertyChanged(new PropertyChangedEventArgs("ItemsFrom"));
                }
            }
        }

        private int _itemsTo;

        public int ItemsTo
        {
            get { return ItemsFrom == 0 ? 0 : ItemsFrom + ItemsPerPage - 1 < TotalItems ? ItemsFrom + ItemsPerPage - 1 : TotalItems; }
            set
            {
                if (_itemsTo != value)
                {
                    _itemsTo = value;
                    OnPropertyChanged(new PropertyChangedEventArgs("ItemsTo"));
                }
            }
        }

        #endregion

        #region Constructor
        public PaginatedObservableCollection(IEnumerable<T> collection)
        {
            _originalCollection = new List<T>(collection);
            _currentPage = 1;
            _itemsPerPage = 10;
            CalculateTotalPages();
            RecalculateItemsPerPage();
        }

        public PaginatedObservableCollection(int itemsPerPage)
        {
            _itemsPerPage = itemsPerPage <= 0 ? 1 : itemsPerPage;
            _originalCollection = new List<T>();
        }
        public PaginatedObservableCollection()
        {
            _originalCollection = new List<T>();
        }
        #endregion

        #region Private
        private void RecalculateItemsPerPage()
        {
            Clear();

            var startIndex = _currentPage * _itemsPerPage - _itemsPerPage;

            for (var i = startIndex; i < startIndex + _itemsPerPage; i++)
            {
                if (_originalCollection.Count > i)
                {
                    base.InsertItem(i - startIndex, _originalCollection[i]);
                }
            }

        }

        private void CalculateTotalPages()
        {
            var itemCount = _originalCollection.Count;
            var thisMod = itemCount % _itemsPerPage;
            var thisDiv = itemCount / _itemsPerPage;

            TotalPages = thisMod == 0 ? thisDiv : thisDiv + 1;
        }

        #endregion

        #region Overrides

        protected override void InsertItem(int index, T item)
        {
            var startIndex = _currentPage * _itemsPerPage;
            var endIndex = startIndex + _itemsPerPage;

            //Check if the Index is with in the current Page then add to the collection as bellow. And add to the originalCollection also
            if ((index >= startIndex) && (index < endIndex))
            {
                base.InsertItem(index - startIndex, item);

                if (Count > _itemsPerPage)
                {
                    base.RemoveItem(endIndex);
                }
            }

            if (index >= Count)
            {
                _originalCollection.Add(item);
            }
            else
            {
                _originalCollection.Insert(index, item);
            }
        }

        protected override void RemoveItem(int index)
        {
            var startIndex = _currentPage * _itemsPerPage;
            var endIndex = startIndex + _itemsPerPage;

            //Check if the Index is with in the current Page range then remove from the collection as bellow. And remove from the originalCollection also
            if ((index >= startIndex) && (index < endIndex))
            {
                RemoveAt(index - startIndex);

                if (Count <= _itemsPerPage)
                {
                    base.InsertItem(endIndex - 1, _originalCollection[index + 1]);
                }
            }

            _originalCollection.RemoveAt(index + (_currentPage - FistPage) * _itemsPerPage);

            CalculateTotalPages();

            RecalculateItemsPerPage();
        }

        #endregion

    }

}



Create a collection (In viewModel)

Articles =
            await
                TaskEx.Run(
                    () => new PaginatedObservableCollection<Article>(_articleService.GetList()));

Delete a element (In viewModel)

Articles.Remove(selectedArticle);



DataGridComboBoxColumn SelectionChanged event in WPF using MVVM

$
0
0
How to handle DataGridComboBoxColumn SelectionChanged event in WPF using MVVM ?

How to Show busy indicator in TabItem header

$
0
0

Hi,

In my application have used tab control and i need to show busy indicator in tab item header when tabcontent loading .  how to achieve this in MVVM  ?


MouseOver action on a control should display text in the textbox of different control

$
0
0

I have a toolbar control and a status bar control. When I hover on items in the tool bar control, I want to display some helpful text in the text box control inside status bar control.

        <StackPanel DockPanel.Dock="Top" Orientation="Vertical" DataContext="{Binding ToolBars}">
            <ToolBarTray DockPanel.Dock="Top" IsLocked="True" Background="Gainsboro">
                <ToolBar DataContext="{Binding [0]}" Background="Gainsboro"
                             ItemsSource="{Binding Path=Items}" 
                             ItemTemplateSelector="{StaticResource ToolBarItemTemplateSelector}" 
                             IsEnabled="{Binding IsEnabled}"
                             Visibility="{Binding IsVisible, Converter={StaticResource BooleanToVisibilityConverter}, FallbackValue='Collapsed'}"/>
                <ToolBar DataContext="{Binding [1]}" Background="Gainsboro"
                             ItemsSource="{Binding Path=Items}" 
                             ItemTemplateSelector="{StaticResource ToolBarItemTemplateSelector}" 
                             IsEnabled="{Binding IsEnabled}" 
                             Visibility="{Binding IsVisible, Converter={StaticResource BooleanToVisibilityConverter}, FallbackValue='Collapsed'}"/>
            </ToolBarTray>
        </StackPanel>
        <controls:StatusBar DockPanel.Dock="Bottom"></controls:StatusBar>

Xaml for status bar control

<UserControl ....>

    <Grid>
        <StatusBar DockPanel.Dock="Bottom" DataContext="{Binding StatusBar}">
        <StatusBar.ItemsPanel>
            <ItemsPanelTemplate>
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="50" />
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="50" />
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="50" />
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="70" />
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="140" />
                    </Grid.ColumnDefinitions>
                </Grid>
            </ItemsPanelTemplate>
        </StatusBar.ItemsPanel>
        <StatusBarItem>
               <TextBlock Text="{Binding StatusMessage}"> <!-- This is where I want to display message when hovered on tool bar item-->
                </TextBlock>
            </StatusBarItem>
        <StatusBarItem Grid.Column="1">
                <TextBlock Text="{Binding IsCapsLocked, Converter={StaticResource LockKeysConverter}, ConverterParameter={x:Static Key.CapsLock}}"/>
            </StatusBarItem>
        <Separator Grid.Column="2" />
        <StatusBarItem Grid.Column="3">
             <TextBlock Text="{Binding IsNumberLocked, Converter={StaticResource LockKeysConverter}, ConverterParameter={x:Static Key.NumLock}}"/>
        </StatusBarItem>
        <Separator Grid.Column="4" />
        <StatusBarItem Grid.Column="5">
            <TextBlock Text="{Binding IsScrollLocked, Converter={StaticResource LockKeysConverter}, ConverterParameter={x:Static Key.Scroll}}"/>
        </StatusBarItem>
        <Separator Grid.Column="6" />
        <StatusBarItem Grid.Column="7">
            <TextBlock Text="{Binding CurrentDate}"/>
        </StatusBarItem>
        <Separator Grid.Column="8" />
        <StatusBarItem Grid.Column="9">
            <TextBlock Text="{Binding CurrentTime}"/>
        </StatusBarItem>
    </StatusBar>
    </Grid>
</UserControl>

i want to property binding in image control in WPF using property get source of image

$
0
0

<image source={Binding ImageProperty}  />

public string ImageProperty

{

   get { return @"D:\ProjectDemo\Image\imgsport.png"}

I want to  this return valur dynamicly call . Not use locat drive address like:    D:\ProjectDemo\.....

I want to Uri source used for dynamicly return valu of  image.

Thanks,

Window 10 operating system issue with resolution

$
0
0

Placing a control in UI happens different in different operating system.Below images shows for windows 10 system. 

 In case window 7,no issue with it.

Xaml code for button and tab control(overlap):

<ButtonGrid.Column="1"Background="Transparent"Margin="0,0,18,0"HorizontalAlignment="Right"Height="30"Width="30"VerticalAlignment="Center"BorderBrush="Transparent"Click="Settings_Click"Style="{DynamicResource ButtonStyle1}"><Button.ToolTip><TextBlockMargin="-7,-5"Padding="7,5"Foreground="White"Text="{Binding Configuration}"TextWrapping="Wrap"></TextBlock></Button.ToolTip><ImageSource="/Resources/017.png"></Image></Button><ContentControlContent="{Binding Mode=OneWay}"DataContext="{Binding ActiveVM}"Margin="-1,49,1,1"Grid.RowSpan="2"/>

How to use dependency property declared in one class to bind a label in another class in wpf (display in another label )

$
0
0

I have two classes Radial.xaml.cs and ToothDimension.xaml.cs, want to bind value of the class Radial.xaml.cs textbox control to the dependency property of another class ToothDimension.xaml.cs which works fine. It's not getting bound to text box control. Do I need to change DataContext in Radial.xaml.cs? I tried this:

Radial.xaml.cs

publicRadial(){InitializeComponent();DataContext=newToothDimension();}

Radial.xaml

<Labelx:Name="Length"Text="{Binding Path=ToothHeight}"HorizontalAlignment="Left"Height="35"/>

ToothDimension.xaml.cs (in which ToothHeight is declared)

publicDoubleToothHeight{get{return(double)GetValue(ToothHeightProperty);}set{SetValue(ToothHeightProperty, value);}}publicstaticreadonlyDependencyPropertyToothHeightPropertyDependencyProperty.RegisterAttached("ToothHeight",typeof(double),typeof(ToothDimensions),newPropertyMetadata(newPropertyChangedCallback(ToothHeightChanged)));privatestaticvoidToothHeightChanged(DependencyObject d,DependencyPropertyChangedEventArgs e){double value =(double)e.NewValue;ToothMeasurements thisControl = d asToothMeasurements;}


Does MS really care about these forums?

$
0
0
With the amount of time the "service is down" I would say not, but I would love to hear from a MS person on this subject.

Lloyd Sheen

WPF System.Windows.Media.RenderCapability.Tier Reports 0 on new nVidia 1050ti

$
0
0

While developing a WPF application using

1) Visual Studio 2015

2) Windows 10 Pro (latest version)

3) nVidia 1050ti (4 gig video Ram - latest drivers)

4) DirectX 12 (latest version)

System.Windows.Media.RenderCapability.Tier is returning 0 - no hardware acceleration support.

I have tried disabling all services (thinking perhaps a Remote Desktop Driver is intercepting the Video), changing the .net versions of the app (currently 4.6.1), reinstalling graphics drivers,updating system Codecs, and checked all BIOS settings. dxDiag reports Direct3d Acceleration is available, but there is no GPU usage shown in ths IDE Performance Tools, and the no DirectX objects appear on screen unless I fall back to Software Rendering in code.

This GPU is a new release from nVidia, and perhaps their drivers are acting up, but the nVidia Control Panel and the dxDiag report everything is working fine. Obviously the DirectX version, shaders and texture units are sufficient with this new card. Still no hardware acceleration in WPF app.

Any recommendations for fixing this would be appreciated.


Bob DeCuir

The Easy Shortcut Way Too Write....

$
0
0

Good Evening,

I have some things want to do it but...

i don't know how to solve this way

Example:

I have a A Label

I have a B Label

I have a C Label

If A or B or C have "error" word.

After Button Click"MessageBox.Show(You have some error)"

Else

{

"MessageBox.Show(register successful )"

}

How to write it this way? Did Any want know about it??


Junior C Sharp WPF


Bind object collection to respective usercontrol inside Grid?

$
0
0

Hello,

I have a collection of ChildViewModel inside a ParentViewModel class. I am bindingParentViewModel class to a grid. Inside the grid control, i have a 4 rows and 4 columns and each cell inside has a UserControl so there are total 16 usercontrols inside the grid and 16ChildViewModel objects inside ParentViewModel

Each ChildViewModel class has a 'RowIndex' and 'ColumnIndex' property which i want to use for bindingChildViewModel class to usercontrol. According to RowIndex and ColumnIndex the respective UserControl will bind to matching ChildViewModelclass.

How i can bind the collection of ChildViewModel objects to each respective UserControl inside grid?

Thanks,

IamHuM

Separate receiving data from the view

$
0
0

hello,

my application receiving data continuously (about every 20ms) from my device via serial.

Below the diagram of how I structured my application:

public class MyProtocol
{
    Thread myThread;
    public event DataChangedHandler DataChanged;

    public MyProtocol() {
    }
    protected virtual void OnDataChanged() {
        if (DataChanged != null)
            DataChanged(this, e);
    }
    public void GetData(List<byte[]> address) {
        myThread = new Thread(this.TraceThreadProc);
        //...
        //...
        myThread.Start();
    }
    protected void TraceThreadProc() {
        //...
        //...
        do
        {
            //...
            //...
            // Callback mapped on my GUI application
            OnDataReady(// data read from protocol);

        } while (stopRequest == false);
    }
}

public class MyWPFViewModel {
    protected void OnDataReady(/* data read from protocol */) {
        if (numberOfDataReceived % 10 == 0) {
            ShowData();
        }
    }
    private void ShowData() {
        // Fill DataTable in binding with GridView with data.
    }
}

my thread continuosly transmit of my GUI application data called callback method (OnDataReady). In my method (OnDataReady) I would every 10 packets received view them but does not affect the receive thread data.

I'd like some advice on what data structure used to save the cache of 10 packets waiting to display and how to make thread safe this structure if needed.

thanks,

Stefano


How do I setup Menu control in DataGrid instead of ComboBox in WPF Using MVVM ?

$
0
0

How do I setup Menu control in DataGrid instead of ComboBox in WPF Using MVVM ?

My Requirement is :

  1. Each each product have different set of LicenseActions based on the business rules and want to used MenuControl instead of ComboBox.How to bind items with MenuControl in DataGrid using MVVM pattern.
  2. How to handle MenuControl click event using MVVM pattern ?
  3. Want to handle the visibility and Tooltip of MenuItem based on the business rules. How to setup this in MVVM ? 

I have a ViewModel (LicenseInventoryViewModel) that exposes a public property listing all 'Product' for the DataGrid.

public class LicenseInventoryViewModel : ViewModelBase
{
  public ObservableCollection<Product> Products()
  {
     // Implementation
  }
}
public class Product : ViewModelBase
{
  public string Product { get; set; }
  public string LicenseType { get; set; }
  public string Status { get; set; }
  public string Expires { get; set; }
  public List<LicenseAction> LicenseActions { get; set; }
}

public class LicenseAction { public string ActionId { get; set; } public string ActionName { get; set; } public Visibility Visibility { get; set; } public bool IsEnabled { get; set; } public string ToolTip { get; set; } }

// possible license actions { Activate, Deactivate, View Details, View History }


Kindly request you to share your experience and best practises. So I can implement this requirement in best way.


Change Page Switching Between Different Page

$
0
0

hi, i'm trying to develop a simply game, in the first page i must show some simply write such as (play, settings, exit).

then, when the user made a choice, a must call another wpf page but not with another thread but changing the page that i'm now viewing.

How should i work?

ContextMenu and Hierachicaldatatemplate Binding

$
0
0

In the MainWindow I have an ObservableCollection of "parent" items. Every parent, has an ObservableCollection of "device" items.

The first level of my ContextMenu is properly bind to the items of the first Collection. The problem is, for every MenuItem I am getting always the same results (meaning that the datacontext for each MenuItem is always the same "parent"?)

To better understand, the contextmenu looks like this (sorry, I can't attach any picture or link)

MenuItem1 -> SubItemA
MenuItem2    SubItemB
             SubItemC
________________________

MenuItem1
MenuItem2 -> SubItemA
             SubItemB
             SubItemC
Every MenuItem I open, I always get the same SubItems.


And here is the XAML code:

<StackPanel.Resources><CollectionViewSource Source="{Binding Parents}" x:Key="Parents"/><HierarchicalDataTemplate DataType="{x:Type local:parent}"><HierarchicalDataTemplate.ItemsSource><Binding><Binding.Source><CompositeCollection><MenuItem Header="ParentStartAll"/><MenuItem Header="ParentStopAll"/><MenuItem Header="ParentRestartAll"/><Separator/><CollectionContainer Collection="{Binding Childs, Source={StaticResource Parents}}"/></CompositeCollection></Binding.Source></Binding></HierarchicalDataTemplate.ItemsSource><TextBlock Text="{Binding Path=Name}"/></HierarchicalDataTemplate><HierarchicalDataTemplate DataType="{x:Type local:device}"><HierarchicalDataTemplate.ItemsSource><Binding><Binding.Source><CompositeCollection><MenuItem Header="StartAll"/><MenuItem Header="StopAll"/><MenuItem Header="RestartAll"/><Separator/><CollectionContainer Collection="{Binding Processes, Source={StaticResource Parents}}"/></CompositeCollection></Binding.Source></Binding></HierarchicalDataTemplate.ItemsSource><TextBlock Text="{Binding Path=Name}"/></HierarchicalDataTemplate>


        [...]


    </StackPanel.Resources><StackPanel.ContextMenu><ContextMenu DataContext="{Binding Path=PlacementTarget.Tag, RelativeSource={RelativeSource Self}}" ItemsSource="{Binding Parents}"></ContextMenu></StackPanel.ContextMenu>

What am I doing wrong? Also, when I try to open the ContextMenu for the second time, it only shows the first level (only the "parents").

Any hint?

Pretty newbie here, so please don't angry if the question is too easy or if I made some ugly mistakes. I have to say it was not easy to manage the binding in the firstplace and I am struggling to get this contextmenu working.

Thanks a lot.


Viewing all 18858 articles
Browse latest View live


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