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

Image showing in Visual Studio Designer but not at run time.

$
0
0

I am creating a multi window application in which it has an about window.

I am trying to add some images in it. my images are in a folder Named Image and properties are following -

Build Action = Resource

Copy To Output Directory = Do not copy

I am using following code to add image in window.

<Image Source="pack://application,,,/Images/ICO0.png" Stretch="None" Grid.Row="1"  Margin="2" />

 where ICO0 is the name of the image.

Problem is Image is showing fine in Visual Studio Designer but not at run time.

I using same code and image in two other window and there is no problem.

And this code is also running fine

<Image Source="D:\......\Images\ICO1.png" Stretch="None" Grid.Row="1"  Margin="2" />


Nehal Ahmad


Memory held by the resources is not released even after disposing all the references in WPF

$
0
0

Hi,

I created a byte array, memory stream and BitmapImage when a main page is loaded as in the below snippet.

  public partial class MainWindow : Window
    {
        byte[] buffer;
        Stream stream;
        BitmapImage bitmap;
        public MainWindow()
        {
            InitializeComponent();
            this.Loaded += MainWindow_Loaded;
        }

        private void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            buffer = new byte[100000000];
            stream = new MemoryStream(buffer);
            bitmap = new BitmapImage();
            bitmap.BeginInit();
            bitmap.UriSource = new Uri(@"Image file Path");
            bitmap.EndInit();
        }
}

When the main page is loaded, I noted down the memory (using Visual Studio Diagnostic tool) is raised to160 MB

I wrote a button click event and cleared all the resources properly in the event handler as in the below code snippet.

        private void button_Click(object sender, RoutedEventArgs e)
        {
            Array.Clear(buffer, 0, buffer.Length);
            buffer = null;
            stream.Close();
            stream.Dispose();
            bitmap.UriSource = null;
            bitmap = null;
}

When test the memory in Visual Studio Diagnostic tool, I could see that the memory held by the resources is not released even after cleared and the memory stays at160 MB.

When tried to call the Garbage collection as in the below code snippet, I could see only 5 MB is reduced and the memory still stays at155 MB.

            GC.Collect();
            GC.WaitForPendingFinalizers();

I suspect memory leak in this. Can you please suggest me how to release the total memory held by the resources?

Regards,

Deepak G


WPF Grid Problem

$
0
0

This is wrappanel and as i want it to be.

This is Grid. How can i add many usercontrols into the grid as it is above?




How to modify the contents of a WPF page in real time?

$
0
0

I want to rotate a picture using angles stored in an array.

I tried a for loop with a delay function but it is not updating the new rotating angles.

        public Page4()
        {
            InitializeComponent();
            Rotate();
        }
        public void Rotate()
        {
            int[] Angles = new int[] { 15, 17, 25, 35, 40, 35, 33, 21 };
            for (int i = 0; i < Angles.Length; i++)
            {

            
            RotateTransform rotateTransform = new RotateTransform(Angles[i]);
            FRONTFRONT_png.RenderTransform = rotateTransform;
            RotateTransform rotateTransform2 = new RotateTransform(Angles[i]);
            LEFTLEFT_png.RenderTransform = rotateTransform2;
                Task.Delay(1000);
            }

        }

    }

     

Displaying DirectX (SharpDX.Windows.RenderForm) within a WPF appication

$
0
0

We try to display a live stream of an rtsp camera within a WPF application. Performance is critical in our application, and we try to display a directX window within the WPF application.

My code looks as following:

fn =@"rtsp://192.168.4.104:554/stream0";//Camera urlvar player =Player.Create(fn);

enter image description here

The constructor of the player looks as following:

enter image description here

and the play method of the player looks as following:

enter image description here

Remember that the form data member is of type:

enter image description here

The result when I run the program is the following SharpDX window that indeed displays the live stream of the rtsp camera:

enter image description here

Now, what I want to do is to assimilate the directX (SharpDX.Windows.RenderForm) within my WPF appication. I'm looking forward to your suggestions. Thank you!

Collapse/Remove 1 control within a ListBox based on condition

$
0
0
Hi,

I am trying out a use case where a listbox has label and a button. The button should be visible only for the new item until the progressBar is visibile for example. And after that the listbox should have only label.

I tried setting trigger for button to control the visibility, however the trigger is applied to all the items in the list, however i want the button to be visible for the new item that is added.

Any suggestion is appreciated.

Please find below what i tried:

<Style x:Key="ButtonVisibilityStyle" TargetType="{x:Type Button}">
                <Style.Triggers>                    
                   <DataTrigger Binding="{Binding ElementName=ProgressBar, Path=Visibility}" Value="Hidden">
                        <Setter Property="Visibility" Value="Collapsed"/>
                    </DataTrigger>
                </Style.Triggers>
            </Style>
<ListBox Name="SeriesListBox" ItemsSource="{Binding List, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <StackPanel>
                           <Label Name="Label" Content="{Binding Text}"/> 
<Button Name="CanceleButton" Style="{StaticResource ButtonVisibilityStyle}"/> 
                        </StackPanel>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
Thanks in advance.


Stack panel inside menu - design mode?

$
0
0

Hello,

I'm trying to implement a stackpanel inside menu (as MenuItem):

        <DockPanel>            <Menu DockPanel.Dock="Top">                <MenuItem Header="Details">                        <StackPanel Height="81" Name="stackPanel2" Width="193">                            <RadioButton Name="Option_1" Content="Option 1"></RadioButton>                            <RadioButton Name="Option_2" Content="Option 2"></RadioButton>                            <RadioButton Name="Option_3" Content="Option 3"></RadioButton>                        </StackPanel>                </MenuItem>            </Menu>        </DockPanel>

How to get an access to design mode of this stackpanel under XAML?

During normal design work this stackpanel is hided under menu ribbon.

Default SelectedItem is not updated in Combobox

$
0
0

Hi,

I am using ComboBox with bind the Collection with the SelectedItem and using another collection as ItemSource.

When I set the default value for Collection,it is not updated in ComboBox.

Code snippet:

Xaml:

    

 <Window.DataContext>
        <local:ViewModel/>
    </Window.DataContext>

    <Window.Resources>       
        <local:ShipCityDetailsRepository x:Key="ShipCityName"/>
    </Window.Resources>
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition/>
            <ColumnDefinition  Width="150"/>
        </Grid.ColumnDefinitions>
        <ComboBox Height="30" Width="100"
            SelectedItem="{Binding SelectedShipCity, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
            ItemsSource="{StaticResource ShipCityName}" />

    </Grid>

Model contains two cs files:

OrderInfo.cs:

using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SfDataGrid_ComboBoxDemo
{
    public class OrderInfo : INotifyPropertyChanged
    {
        #region Private members

        private int productId;
        private string _productName;
        private double _NoOfOrders;
        private DateTime _orderDate;
        private string countryName;
        private ObservableCollection<string> shipCity;// = new ObservableCollection<string>();
        private string _shipCity;


        #endregion

        #region Public properties

        public int ProductId
        {
            get
            {
                return productId;
            }
            set
            {
                productId = value;
                this.RaisePropertyChanged("ProductId");
            }
        }

        public string ProductName
        {
            get
            {
                return _productName;
            }
            set
            {
                _productName = value;
                RaisePropertyChanged("ProductName");
            }
        }

        public double NoOfOrders
        {
            get
            {
                return _NoOfOrders;
            }
            set
            {
                _NoOfOrders = value;
                RaisePropertyChanged("NoOfOrders");
            }
        }

        public DateTime OrderDate
        {
            get
            {
                return _orderDate;
            }
            set
            {
                _orderDate = value;
                RaisePropertyChanged("OrderDate");
            }
        }

        public string CountryName
        {
            get
            {
                return countryName;
            }
            set
            {
                countryName = value;
                RaisePropertyChanged("CountryDescription");
            }
        }

        public string ShipCity
        {
            get
            {
                _shipCity = string.Empty;
                if (SelectedShipCity == null)
                    return _shipCity;
                foreach (var city in SelectedShipCity)
                {
                    if (string.IsNullOrEmpty(_shipCity))
                    {
                        _shipCity = city;
                        continue;
                    }
                    _shipCity += ", " + city;
                }
                return _shipCity;
            }
            set
            {
                _shipCity = value;
                RaisePropertyChanged("ShipCity");
            }
        }

        public ObservableCollection<string> SelectedShipCity
        {
            get
            {
                return shipCity;
            }
            set
            {
                shipCity = value;
                RaisePropertyChanged("SelectedShipCity");
            }
        }
        #endregion

        public OrderInfo()
        {
            this.SelectedShipCity = new ObservableCollection<string>();
        }

        public event PropertyChangedEventHandler PropertyChanged;
        public void RaisePropertyChanged(string propName)
        {
            if (this.PropertyChanged != null)
                this.PropertyChanged(this, new PropertyChangedEventArgs(propName));
        }
    }
}

ShipCityDetailsRepository.cs:

public class ShipCityDetailsRepository : ObservableCollection<string>
    {
         public ShipCityDetailsRepository()
        {
            this.Add("Buenos Aires");
            this.Add("Graz");
            this.Add("Bruxelles");
            this.Add("Campinas");
            this.Add("Montréal");
            this.Add("Århus");
            this.Add("Helsinki");
            this.Add("Lille");
            this.Add("Aachen");
            this.Add("Bergamo");
            this.Add("Cork");
            this.Add("México D.F.");
        }
    }

    public class DisabledShipCityDetailsRepository : ObservableCollection<string>
    {
        public DisabledShipCityDetailsRepository()
        {

            this.Add("Buenos Aires");
            this.Add("Århus");
            this.Add("Helsinki");
            this.Add("Lille");        
            this.Add("México D.F.");
        }
    }    

In ViewModel.cs :

public class ViewModel : INotifyPropertyChanged
    {
        private ObservableCollection<string> shipCity;
        public ObservableCollection<string> SelectedShipCities
        {
            get
            {
                return shipCity;
            }
            set
            {
                shipCity = value;
                RaisePropertyChanged("SelectedShipCities");
            }
        }

        private ObservableCollection<OrderInfo> _orderList;

         

        public ObservableCollection<OrderInfo> OrderList
        {
            get
            {
                return _orderList;
            }
            set
            {
                _orderList = value;
                RaisePropertyChanged("OrderList");
            }
        }

        public ViewModel()
        {
            SelectedShipCities = new ObservableCollection<string> { "Buenos Aires" };
            _orderList = new ObservableCollection<OrderInfo>();
            _orderList.Add(new OrderInfo()
            {
                ProductId = 1001,
                ProductName = "Alice Mutton",
                NoOfOrders = 10,
                OrderDate = new DateTime(2015, 5, 2),
                CountryName = "Argentina",
               SelectedShipCity =  new ObservableCollection<string>() { "Bruxelles" }
            });
           
        }

        public event PropertyChangedEventHandler PropertyChanged;
        public void RaisePropertyChanged(string propName)
        {
            if (this.PropertyChanged != null)
                this.PropertyChanged(this, new PropertyChangedEventArgs(propName));
        }
    }
}

I need to show the  SelectedShipCity =  new ObservableCollection<string>() { "Bruxelles" } this value in viewmodel.cs in my combobox.

Please do the favor to get the solution.


Baffling Sequence of Events

$
0
0

I have a wpf window which allows users to edit financial accounts; the window is populated from my database.

This is the relevant portion of my FinancialAccount class:

Public Class FinancialAccount
   AccountName as String
   Notes as String
   ....
End Class

On the window, the user can click on which account they want to edit from a ComboBox, then the rest of the window is populated with the data for that account and the DataContext is set to fa, the selected instance of the FinancialAccount class. See the following figure.

Let's focus on the Notes field. It is bound in XAML as follows:

<TextBox
   x:Name="txtNotes"
   Text="{Binding Path=Notes}"></TextBox>

and the event handlers for the Exit button and Notes TextBox are:

Private Sub btnExit_Click(sender As Object, e As RoutedEventArgs) Handles btnExit.Click
    Debug.WriteLine($"Exit: {fa.Notes}")
    SaveAccount()
    Close()
End Sub

and

Private Sub txtNotes_LostKeyboardFocus(sender As Object, e As KeyboardFocusChangedEventArgs) Handles txtNotes.LostKeyboardFocus
    Debug.WriteLine($"LostKeyboardFocus: {fa.Notes}")
End Sub

The two Debug statements are important. Now suppose I append "efgh" to the text in the Notes TextBox then click on the Exit button; here is the result of the Debug statements:

LostKeyboardFocus: abcd
Exit: abcd
LostKeyboardFocus: abcdefgh

Of importance here is that the SaveAccount routine is NOT run after the Exit button is clicked so that the new data are NOT sent back to the database.

Questions

 Why does the TextBox LostKeyboardFocus event fire twice? Why is the entered text not bound to the DataContext until the second time the event fires? How can I implement this so that the entered text is actually saved?

How can I create custom control library in .net core 3.0?

$
0
0

I installed Visual Studio 2019 16.1.3 and .net core 3.0 Preview 6.

Now I wanna create a new custom control library now.

However, I can create a .net core WPF APP but can not create a .net core custom control library.

Why it turns out to be this. The Microsoft has not made this yet or I should create it by any other way.

Moreover, .net core 3.0 RC will publish next month in Microsoft's roadmap. So I want to learn more about this. Thank you.

Trying to add rows to Datagrid

$
0
0

Hello,

I have some code that I tried to modify to work for WPF datagrid

Original code here, thank you Xingyu Zhao

 I did my best to convert this code to work for WPF but I'm getting an error when trying to add new rows.

Any help is much appreciated.

 DateTime StartDate = System.Convert.ToDateTime(dteStartDate.SelectedDate);
                DateTime EndDate = System.Convert.ToDateTime(dteEndDate.SelectedDate);
                int yearDiff = EndDate.Year - StartDate.Year;
                int monthAll = 0;              
                if(yearDiff > 0)
                {
                    int monthStart = 12 - StartDate.Month + 1;
                    int monthEnd = EndDate.Month;
                    monthAll = monthStart + monthEnd + 12 * (yearDiff - 1);
                }
                else if(yearDiff == 0)
                {
                    monthAll = EndDate.Month - StartDate.Month + 1;
                }
                else
                {
                    MessageBox.Show("ERROR! End Date must be gretaer than Start Date");
                }
                int month = 0;
                int count = 0;
                for(int i=0; i< monthAll;i++)
                {
                    month = StartDate.Month + i;
                    if(month > 12 + 12* count)
                    {
                        count++;                   
                    }
                    month -= 12 * count;
                    dataGrid1.Items.Add(new Item() { id, $"{month}/1/{StartDate.Year + count}" });
                }

Print Rotated Barcode

$
0
0

Hello,

Does anyone know of a good way to print a rotated (vertical) barcode without losing resolution?

Thank you,

Justair

UserConsentVerifier from WPF

$
0
0

I need to call UserConsentVerifier.CheckAvailabilityAsync() from my WPF App and can find no guidance for doing so.  I can get this code to work:

      await UserConsentVerifier.CheckAvailabilityAsync() == UserConsentVerifierAvailability.Available) 

the pop-up UI comes up in the corner with part of its window cut off. 

Adding this line:

Windows.UI.Xaml.Hosting.WindowsXamlManager.InitializeForCurrentThread();

fixes that problem, but then when I call the ADAL package for the user to login to their Azure AD account, the window comes up blank.  

WPF - get the list of Windows 10 languages

$
0
0
In C# WPF, how to get the list of Windows 10 available languages, I need this to load the dropdown list in WPF.

I see this is available in UWP but I don't find one for WPF. https://social.msdn.microsoft.com/Forums/vstudio/en-US/e2954327-fe9e-484e-95bf-e6b1e3f32858/uwp-howto-show-language-list-with-installed-input-languages-at-the-top?forum=wpdevelop

GridData binding source from ICollectionView not display data

$
0
0

I set ItemSource of my GridData bound from an ICollectionView named "T_Work_View" as a property in my ViewModel "T_Work_SoloViewModel".

I prepare data for it from function "GetTWorkInfo" in "T_Work_SoloViewModel".  I tried making a debug and It's has data but the DataGrid not display it. I tried some solution in Microsoft forum and other site like StackOverFlow but nothing which fit with my question.

I attach some code and image for more detail. I hope someone can give me advise to find out the solution for my question.

Thanks in advance!

- ViewModel "T_Work_SoloViewModel":

  //Property T_Work_View       
        private ICollectionView t_Work_View;
        public ICollectionView T_Work_View {
            set
            {
                t_Work_View = value;
                RaiseNotifyChanged("T_Work_View");
            }
            get
            {
                return t_Work_View;
            }
        }
//Property T_Work_List
 private ObservableCollection<T_Work_Solo> list_T_Work;
        public ObservableCollection<T_Work_Solo> T_Work_List
        {
            get
            {
                return list_T_Work;
            }
            set
            {
                list_T_Work = value;
                RaiseNotifyChanged("T_Work_List");
            }
        }
//function GetData for binding source
 private async void GetTWorkInfo(object obj)
        {
            ObservableCollection<T_Work_Solo> tWorkList = new ObservableCollection<T_Work_Solo>();

            await Task.Run(() =>
            {
                try
                {

                    VisibilityState = Visibility.Visible;
                    tWorkList = T_Work_Solo_BAL.Instance.Get_T_Work_List(DTPStartDate.ToString("yyyyMMdd"), DTPEndDate.ToString("yyyyMMdd"), 1, 50, "");
                    PCDCheckingInfo_List = T_Work_Solo_BAL.Instance.GetPCDCheckingInfoList(DTPStartDate.ToString("yyyy/MM/dd"), DTPEndDate.ToString("yyyy/MM/dd"), 1, 50, "");
                    var result = tWorkList.Join(PCDCheckingInfo_List, t => t.POREQNO, p => p.PO_Name, (t, p) => t);
                    tWorkList.ToList().ForEach(t =>
                    {
                        if (result.Contains(t))
                            t.CheckStatus = "OK";
                        else t.CheckStatus = "NG";
                    });
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Lấy dữ liệu thất bại ! \n Máy chủ hiện quá tải vui lòng thử lại", "Thông báo", MessageBoxButton.OK, MessageBoxImage.Information);
                }

            });

            //ObservableCollection<T_Work_Solo>
            T_Work_List = tWorkList;
            //LoadingIndicator visibility state
            VisibilityState = Visibility.Hidden;


            //Set T_Work_View data
            IList<T_Work_Solo> tWorks = new T_Works(T_Work_List); //mount ObservableCollection<T_Work_Solo> T_Work_List for IList
            T_Work_View = CollectionViewSource.GetDefaultView(tWorks);
            T_Work_View.GroupDescriptions.Add(new PropertyGroupDescription("noGroup"));
        }
        //Event
        public event PropertyChangedEventHandler PropertyChanged;
        public void RaiseNotifyChanged(string propName)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(propName));
        }

- Class "T_Works" to bind CollectionView

 public T_Works(ObservableCollection<T_Work_Solo> T_Work_List)
        {
            foreach (T_Work_Solo t in T_Work_List)
            {
                this.Add(t);
            }
        }

- View "MainWindow.xaml":

<Window x:Class="CheckPCD_JigBush_Watcher.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:CheckPCD_JigBush_Watcher"
        xmlns:vm="clr-namespace:CheckPCD_JigBush_Watcher.ViewModel"     
        xmlns:helpers="clr-namespace:CheckPCD_JigBush_Watcher.Helpers"
        xmlns:sys ="clr-namespace:System;assembly=mscorlib"
        mc:Ignorable="d"
        Title="Theo dõi thông tin PCD" Height="450" Width="800"
        Icon="img/report.png"><Window.DataContext><vm:T_Work_SoloViewModel x:Name="TWorkDataContext"/></Window.DataContext><!--Window Resource--><Window.Resources><!--ViewModel T_Work_Solo--><vm:T_Work_SoloViewModel x:Key="tWorkSoloVM"/><!--Convert Column CheckingStatus in DataGrid--><helpers:CheckStateConverter x:Key="checkstateConverter"/><Style TargetType="{x:Type TextBlock}" x:Key="checkStatusBrush"><Setter Property="Background"><Setter.Value><MultiBinding  Converter="{StaticResource checkstateConverter}"><Binding Path="."/></MultiBinding></Setter.Value></Setter></Style><!--Convert TotalItems in group--><helpers:GroupsToTotalConverter x:Key="groupsToTotalConverter"/><!--CollectionView--><vm:T_Works x:Key="collectionTWorkRef"/><CollectionViewSource x:Key="collectionTWork" Source="{StaticResource collectionTWorkRef}"/></Window.Resources><!--MAIN GRID--><Grid><!--Grid definition--><Grid.RowDefinitions><RowDefinition Height="40"/><RowDefinition/><RowDefinition Height="60"/></Grid.RowDefinitions><Grid.ColumnDefinitions><ColumnDefinition/><ColumnDefinition/></Grid.ColumnDefinitions><!--Sub grid layout--><Grid Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2"><Grid.ColumnDefinitions><ColumnDefinition Width="auto"/><ColumnDefinition/><ColumnDefinition Width="auto"/></Grid.ColumnDefinitions><StackPanel Grid.Row="0" Grid.Column="0"  Orientation="Horizontal"><TextBlock Text="Ngày" FontSize="24" VerticalAlignment="Center"/><DatePicker Name="txtFromDate" SelectedDateFormat="Short" FirstDayOfWeek="Monday" FontSize="18" Margin="2"   SelectedDate="{Binding DTPStartDate,Source={StaticResource tWorkSoloVM}}"  /><TextBlock Text=" ~ " FontSize="24" VerticalAlignment="Center"/><DatePicker Name="txtToDate" FontSize="18" SelectedDateFormat="Short" FirstDayOfWeek="Monday" Margin="2" SelectedDate="{Binding DTPEndDate,Source={StaticResource tWorkSoloVM}, TargetNullValue={x:Static sys:DateTime.Now}}"/><Button Name="btnView" Content="VIEW" BorderThickness="0" Background="#FF4778BF" Foreground="#ffffff"  FontSize="24" Width="100" Margin="0,2,2,2" Command="{Binding CommandGet,Source={StaticResource tWorkSoloVM}}" /></StackPanel><TextBox Grid.Column="1" Name="txtSearch" FontSize="24" Margin="0,2,2,2" VerticalContentAlignment="Center" Text="{Binding SearchValue,Source={StaticResource tWorkSoloVM},Mode=TwoWay}"/><StackPanel Grid.Column="2" Orientation="Horizontal"><Button BorderThickness="0" Width="100" Foreground="#ffffff" Background="#545465" FontSize="24" Margin="0,2,2,2" Command="{Binding CommandSearchText,Source={StaticResource tWorkSoloVM}}" Content="Seach"/><Button BorderThickness="0" Width="100" Foreground="#ffffff" Background="#545465" FontSize="24" Margin="0,2,2,2" Command="{Binding CommandClearText, Source={StaticResource tWorkSoloVM}}" Content="Clear"/></StackPanel></Grid><DataGrid Name="dgvPCDCheckingWatcher" ItemsSource="{Binding T_Work_View,Source={StaticResource tWorkSoloVM}}" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" CanUserAddRows="False"><!--Group--><DataGrid.GroupStyle><GroupStyle><GroupStyle.HeaderTemplate><DataTemplate><DockPanel Background="DarkOliveGreen"><TextBlock Text="{Binding Path=Name,Converter={StaticResource groupsToTotalConverter}}" Foreground="#ffffff" Margin="10,0,0,0"/></DockPanel></DataTemplate></GroupStyle.HeaderTemplate><GroupStyle.ContainerStyle><Style TargetType="{x:Type GroupItem}"><Setter Property="Margin" Value="0,0,0,5" /><Setter Property="Template"><Setter.Value><ControlTemplate TargetType="{x:Type GroupItem}"><Expander BorderBrush="#215525" IsExpanded="True" Background="LightSteelBlue" BorderThickness="0,0,0,1"><Expander.Header><StackPanel Orientation="Horizontal"><TextBlock VerticalAlignment="Center"
															FontWeight="Bold"
															Text="{Binding Path=Name}"
															Width="100" /><TextBlock VerticalAlignment="Center"
															Text="Item count:" /><TextBlock FontWeight="Bold"
															Text="{Binding ItemCount}" /><TextBlock VerticalAlignment="Center"
															TextAlignment="Right"
															Width="100"
															Text="Amount" /><TextBlock FontWeight="Bold"
															VerticalAlignment="Center"
															Text="{Binding Path=Items, Converter={StaticResource groupsToTotalConverter}}" /></StackPanel></Expander.Header></Expander></ControlTemplate></Setter.Value></Setter></Style></GroupStyle.ContainerStyle></GroupStyle></DataGrid.GroupStyle><!--<DataGrid.Columns><DataGridTextColumn Header="TG Bắt đầu" Binding="{Binding WORKSTARTDT,Mode=OneWay, StringFormat=yyyy/MM/dd HH:mm:ss}"/><DataGridTextColumn Header="TG Kết thúc" Binding="{Binding WORKENDDT,Mode=OneWay, StringFormat=yyyy/MM/dd HH:mm:ss}"/><DataGridTextColumn Header="Machine ID" Binding="{Binding MACHINEID, Mode=OneWay}"/><DataGridTextColumn Header="Process ID" Binding="{Binding PROCESSID, Mode=OneWay}"/><DataGridTextColumn Header="Mã PO" Binding="{Binding POREQNO, Mode=OneWay}"/><DataGridTextColumn Header="Item Id" Binding="{Binding ITEMID, Mode=OneWay}" /><DataGridTextColumn Header="Mã NV" Binding="{Binding OPERATORID, Mode=OneWay}"/><DataGridTextColumn Header="Trạng thái" Binding="{Binding CheckStatus, Mode=OneWay}" ElementStyle="{StaticResource checkStatusBrush}" /></DataGrid.Columns>--></DataGrid><TextBlock Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" VerticalAlignment="Center" Background="#FF4E7BE5" Foreground="#ffffff" HorizontalAlignment="Center" Text="Đang tải dữ liệu, vui lòng chờ ..." FontSize="24" Visibility="{Binding VisibilityState,Source={StaticResource tWorkSoloVM},Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" Padding="10"></TextBlock>        <StackPanel Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2" Orientation="Horizontal"><Button Background="#FF3A3934" BorderThickness="0"  Margin="4" Padding="5" Command="{Binding CommandExportExcel,Source={StaticResource tWorkSoloVM}}"><StackPanel Orientation="Horizontal" ><Image Source="img/excel.png" Stretch="Uniform"/><TextBlock Text="EXCEL" FontSize="24" VerticalAlignment="Center" Foreground="#ffffff"/></StackPanel></Button><Button Content="By Date" Command="{Binding CommandGroupByDate,Source={StaticResource tWorkSoloVM}}"/></StackPanel></Grid><!--END MAIN GRID--></Window>


to prevent over load multiline wrapped TextBox

$
0
0

Hi All.

I'm using VS 2017. In my WPF VB window I have multiline wrapped TextBox and I would like to inform user by popup message that TextBox is full when two lines is completely typed. I will appreciate if someone show how to do that.

Thanks.

Starting Storeboard based on property value

$
0
0

Hi, I did search for a solution to my problem but nothing to do.

I'm using Caliburn Micro into ma project, in the code below I have a image running by the storyboard and a coumple of buttons

and in the view model I have a property of type bool called ValveValue.

Now... when I click a button the property change to true or false depending which button I pressed.

What I would like to do is that when I click on Open button the property become true and the SbActionValve1 start and vice versa, when I click on Close button will start the SbActionValve2 which have different angle trasformation.

I lost a couple of days to resolve this problem so I will appreciate your help.

Thanks

  

<UserControl x:Class="WpfApp1.Views.ShellView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:WpfApp1.Views"
             xmlns:cal="http://www.caliburnproject.org"
             mc:Ignorable="d" Width="582.716" Height="139.506">
    
    <UserControl.Resources>
        <Storyboard x:Key="SbActionValve1">
            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle)" Storyboard.TargetName="imgProp">
                <EasingDoubleKeyFrame KeyTime="0" Value="0"/>
                <EasingDoubleKeyFrame KeyTime="0:0:0.8" Value="360"/>
            </DoubleAnimationUsingKeyFrames>
        </Storyboard>
        <Storyboard x:Key="SbActionValve2">
            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle)" Storyboard.TargetName="imgProp">
                <EasingDoubleKeyFrame KeyTime="0" Value="0"/>
                <EasingDoubleKeyFrame KeyTime="0:0:0.8" Value="0"/>
            </DoubleAnimationUsingKeyFrames>
        </Storyboard>
    </UserControl.Resources>   
    

    <Grid Background="#FFD4D4D4">

        <Image x:Name="imgProp" Source="/WpfApp1;component/Images/propeller.png" Margin="25,34,457,33" RenderTransformOrigin="0.5,0.5">
            <Image.RenderTransform>
                <TransformGroup>
                    <ScaleTransform/>
                    <SkewTransform/>
                    <RotateTransform/>
                    <TranslateTransform/>
                </TransformGroup>
            </Image.RenderTransform>

        </Image>

        <!--Button Open Valve-->
        <Button cal:Message.Attach="SetValve('true')"  Content="Open" HorizontalAlignment="Left" Margin="339,54,0,0" VerticalAlignment="Top" Width="75"/>

        <!--Button Close Valve-->
        <Button cal:Message.Attach="SetValve('false')" Content="Close" HorizontalAlignment="Left" Margin="427,54,0,0" VerticalAlignment="Top" Width="75"/>


        <TextBox x:Name="textBox" Text="{Binding Path=ValveValue}"  Margin="177,54,280,58">
            <TextBox.Style>
                <Style TargetType="{x:Type TextBox}">
                    <Setter Property="Foreground" Value="#FFE8E8E8"/>
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding ValveValue}" Value="True">
                            <Setter Property="Foreground" Value="Green"/>
                        </DataTrigger>
                        <DataTrigger Binding="{Binding ValveValue}" Value="False">
                            <Setter Property="Foreground" Value="Red"/>
                            <DataTrigger.EnterActions>
                                <BeginStoryboard Storyboard="{StaticResource SbActionValve1}"/>
                            </DataTrigger.EnterActions>
                            <DataTrigger.ExitActions>
                                <BeginStoryboard Storyboard="{StaticResource SbActionValve2}"/>
                            </DataTrigger.ExitActions>
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </TextBox.Style>
        </TextBox>

    </Grid>

</UserControl>



Gioking http://social.msdn.microsoft.com/Forums/en-US/user

ToolTipService.BetweenShowDelay still not working after 9+ years?!

$
0
0

Greetings!

The ToolTipService.BetweenShowDelay property is defined as:
"[...] the maximum time between the display of two tooltips where the second tooltip appears without a delay."

In other words, if one tooltip opens and the user moves the mouse cursor to another element within the specified time, then the tooltip of said second element shows without any delay.

Annoyingly, this does not work at all. Please have a look at the following example:

<StackPanel Orientation="Horizontal"><Button Content="Button1"
            ToolTipService.InitialShowDelay="1000" 
            ToolTipService.BetweenShowDelay="1"><ToolTipService.ToolTip><TextBlock>ToolTip1</TextBlock></ToolTipService.ToolTip></Button><Button Content="Button2" 
            ToolTipService.InitialShowDelay="1000" 
            ToolTipService.BetweenShowDelay="1"><ToolTipService.ToolTip><TextBlock>ToolTip2</TextBlock></ToolTipService.ToolTip></Button></StackPanel>

Hover the mouse over either one of the buttons and wait for the tooltip to open. Now wait for a little while and then move the mouse to the other button. You should notice that the tooltip opensimmediately.

No matter what I do, the BetweenShowDelay won't work. I'm desperate to disable these "quick tooltips", i.e. if the mouse moves over to another element, the next tooltip is not shown befor its InitialShowDelay has expired.

Let's say you have a large toolbar with many items. With the current behavior, tooltips will open everywhere once the user has opened one of them and then moves the mouse.This can severely degrade user experience!

It seems that this issue was discussed years ago - please refer here:
https://social.msdn.microsoft.com/Forums/vstudio/en-US/e396c760-9b49-45c4-bda1-362f2130634d/how-to-disable-betweenshowdelay?forum=wpf

Some workarounds have been discussed. I haven't bothered to try any of them because I deem none of them appropriate, as this is clearly a responsibilty of the ToolTipService.

Could you please have a look at this?! It's really frustrating...

Thank you very much for your support!

Best regards

Hosting a Microsoft Win32 Window in WPF vs Hosting WPF Content in a Microsoft Win32 Window

$
0
0
I am developing a C++ game engine using WPF C# for my game editor. I do know that there is tutorials on how do these two option (Hosting a Microsoft Win32 Window in WPF vs Hosting WPF Content in a Microsoft Win32 Window). But I do not know which approach should I go for that is suitable for my case. Not really sure what's the pros and cons for each option.

UCEERR_RENDERTHREADFAILURE at PresentationCore.dll!System.Windows.Media.Composition.DUCE.Channel.SyncFlush()

$
0
0

My application renders its content with D3D11 and I present it with a D3D11Image from WPFDXInterop.

Sometimes when a Monitor is unplugged or when WIN+P is used to change the Projection options, my application crashes with UCEERR_RENDERTHREADFAILURE.

I could reproduce the same behaviour with the SharpDX Samples "WPFHost". Instead of using the D3D11Image, it uses the D3DImage directly. So it seems that the problem is unrelated to my application and WPFDXInterop and is caused by the D3DImage or WPF.

I have tried to listen to SystemEvents.DisplaySettingsChanging or WM_DISPLAYCHANGE and stop rendering for 5 seconds but it had no effect.

What fixes or workarounds can I use to prevent my application from crashing.

Example stacktrace:

System.Runtime.InteropServices.COMException: 'UCEERR_RENDERTHREADFAILURE (HRESULT: 0x88980406)'

PresentationCore.dll!System.Windows.Media.Composition.DUCE.Channel.SyncFlush()
PresentationCore.dll!System.Windows.Interop.HwndTarget.UpdateWindowSettings(bool enableRenderTarget, System.Windows.Media.Composition.DUCE.ChannelSet? channelSet)
PresentationCore.dll!System.Windows.Interop.HwndTarget.UpdateWindowPos(System.IntPtr lParam)
PresentationCore.dll!System.Windows.Interop.HwndTarget.HandleMessage(MS.Internal.Interop.WindowMessage msg, System.IntPtr wparam, System.IntPtr lparam)
PresentationCore.dll!System.Windows.Interop.HwndSource.HwndTargetFilterMessage(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam, ref bool handled)
WindowsBase.dll!MS.Win32.HwndWrapper.WndProc(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam, ref bool handled)
WindowsBase.dll!MS.Win32.HwndSubclass.DispatcherCallbackOperation(object o)
WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate callback, object args, int numArgs)
WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.TryCatchWhen(object source, System.Delegate callback, object args, int numArgs, System.Delegate catchHandler)
WindowsBase.dll!System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority priority, System.TimeSpan timeout, System.Delegate method, object args, int numArgs)
WindowsBase.dll!MS.Win32.HwndSubclass.SubclassWndProc(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam)
[Native to Managed Transition]
[Managed to Native Transition]
WindowsBase.dll!MS.Win32.HwndSubclass.DefWndProcWrapper(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam)
[Native to Managed Transition]
[Managed to Native Transition]
WindowsBase.dll!MS.Win32.HwndSubclass.SubclassWndProc(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam)
[Native to Managed Transition]
[Managed to Native Transition]
WindowsBase.dll!MS.Win32.HwndSubclass.DefWndProcWrapper(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam)
[Native to Managed Transition]
[Managed to Native Transition]
WindowsBase.dll!MS.Win32.HwndSubclass.SubclassWndProc(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam)
[Native to Managed Transition]
[Managed to Native Transition]
WindowsBase.dll!System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame frame)
PresentationFramework.dll!System.Windows.Application.RunDispatcher(object ignore)
PresentationFramework.dll!System.Windows.Application.RunInternal(System.Windows.Window window)
WPFHost.exe!WPFHost.App.Main()

Viewing all 18858 articles
Browse latest View live


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