Posts

How to create TextBox in wpf that does not accept number using MVVM?

Image
Method 1: Using Model Property Inside View <TextBox Width="200" Text="{Binding MainWindowModel.NonNumeric,UpdateSourceTrigger=PropertyChanged}"> Inside Model  private string _nonNumeric;         public string NonNumeric         {             get { return _nonNumeric; }             set             {                 int intvalue;                 if (!int.TryParse(value[value.Length - 1].ToString(), out intvalue))                     SetProperty(ref _nonNumeric, value);                 else                     value = _nonNumeric;             }         } Method 2 : Using Command Inside View <Window x:Class="PrismDemo.Views.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.openxmlf

How to create Own Semaphore?

 class CustomSemaphore     {         private Mutex[] arrMutex;         // place holder to store thread to mutex mapping         private Thread[] arrthread;         // number of threads allowed to access the resources         private int threadLimit;         // contructor creates the mutexes         public CustomSemaphore(int threadLimit)         {             this.threadLimit = threadLimit;             arrMutex = new Mutex[this.threadLimit];             arrthread = new Thread[this.threadLimit];             for (int i = 0; i < this.threadLimit; i++)             {                 arrMutex[i] = new Mutex();                 arrthread[i] = null;             }         }         public int Wait()         {             int index = WaitHandle.WaitAny(arrMutex);             if (index != WaitHandle.WaitTimeout)                 arrthread[index] = Thread.CurrentThread;             return index;         }         public void Release()         {             for

Write a method for division of two number without using division (‘/’) operator in C#.

    void DivideWithoutDivisionOperator(int divident,int divisior)         {             int quotient = 0;             bool isNegative = false;             if (divident < 0)//if negative             {                 divident = -divident;//make positive                 if (divisior < 0)//if negative                     divisior = -divisior;//make positive                 else                     isNegative = true;             }             else if (divisior < 0)//if negative             {                 divisior = -divisior;//make positive                 isNegative = true;             }             while(divident>=divisior)             {                 divident =divident- divisior;                 quotient++;             }             if (isNegative == true)//if negative                 quotient = -quotient;//make result as negative             Console.Write("Quotient"+quotient+" Reminder " + divident);         }

Filter DataGrid and ListView in wpf using ICollectionView

Image
EmployeeDetails.xaml <UserControl x:Class="PrismMain.Views.EmployeeDetails"         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:PrismMain.Views"         mc:Ignorable="d"        >     <Grid HorizontalAlignment="Stretch" VerticalAlignment="Top" Margin="0,50,0,0">         <Grid.RowDefinitions>             <RowDefinition Height="50"/>             <RowDefinition Height="*"/>             <RowDefinition Height="*"/>         </Grid.RowDefinitions>         <StackPanel Orientation="Horizontal" HorizontalAlignment="Right"

How to use Prism Region in WPF?

Image
Step 1: Install Prism.Core,Prism.DryIoc (You can use any IOC like Prism.Unity),Prism.Wpf. Step 2: Add the prism namespace to  MainWindow.xaml   like below                            xmlns:prism="http://prismlibrary.com/" Step 3: Add ContentControl  to  MainWindow   and initilize the RegionName <Grid>         <ContentControl prism:RegionManager.RegionName =" MainRegion "/>     </Grid> Step 4: Implement IModule  class MainModule : IModule     {         public void OnInitialized (IContainerProvider containerProvider)         {            var region= containerProvider.Resolve<IRegionManager>();             region.RegisterViewWithRegion(" MainRegion ", typeof( TabView ));            // TabView is the view  or UserControl which will inject to Region         }         public void RegisterTypes(IContainerRegistry containerRegistry)         {                   }     } Step 5: App class should inherit from PrismAppl