Posts

Showing posts from 2019

Easy way of navigate using Prism in WPF

Image
1. First.xaml <UserControl x:Class="PrismMain.Views.First"              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:PrismMain.Views"              mc:Ignorable="d"              xmlns:prism="http://prismlibrary.com/"         prism:ViewModelLocator.AutoWireViewModel="True">     <StackPanel>           <Button Content="Navigate To Second" Margin="5"  Command="{Binding NavigateCommand}" Width="150"/>     </StackPanel> </UserControl> First.xaml.cs public partial class First: UserControl     {         pu

How to Create TabControl using Prism Region

Image
MainWindow <metro:MetroWindow 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.openxmlformats.org/markup-compatibility/2006"         xmlns:local="clr-namespace:PrismDemo.Views"         mc:Ignorable="d" xmlns:prism="http://prismlibrary.com/"         Title="MetroPrismDemo"         xmlns:metro="http://metro.mahapps.com/winfx/xaml/controls">     <Grid>         <TabControl Margin="5" prism:RegionManager.RegionName =" TabRegion "                   VerticalAlignment="Stretch" HorizontalAlignment="Left" BorderThickness="0">         </TabControl>     </Grid> </metro:Metr

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

Is it possible not to implement interface method in implementation class?

Yes, it is indeed possible to avoid implementing interface methods in the implementation class. To achieve this, you can declare the methods you don't wish to implement as abstract within the interface. By doing so, you'll need to mark the class as abstract as well. This allows you to provide the implementation of the method in a derived class of the abstract class. Let's take an example scenario using C#: interface ITest  {         void Sum();  } abstract class SumTest : ITest  {        public abstract void Sum();  } In this code, the SumTest don't have the implementation of the Sum() method. This approach can be useful when you require a method implementation but don't want to provide it immediately. By using the abstract modifier, you're indicating that derived classes should implement this method. This flexibility is particularly helpful when you want to delay the implementation until a more appropriate time. abstract class Test : SumTest  {  

What is Abstraction in C#?

The process of defining a class by providing the necessary and essential details of an object to the outside world and hiding the unnecessary things is called abstraction in C#. In C# we can hide the member of a class by using private access modifiers. Let us understand this with a car example. As we know a car is made of many things, such as the name of the car, the color of the car, gear, breaks, steering, silencer, diesel engine, the battery of the car, engine of the car, etc. Now you want to ride a car. So to ride a car you should know function of Gear,Break and Steering you no need to know engine of the car.so here in case of abstraction we can hide engine details so to do that make engine function private inside class and all require thing what we should know make it's function public.

Different type of TextBox available in MahApp.Metro

Image
   1.    <TextBox Text=" Standared textBox " Width="200" Margin="5" />    2.   <TextBox metro:TextBoxHelper.ClearTextButton="True"            Text=" TextBox With Clear Button "    Width="200" Margin="5"/>   3.   <TextBox Style="{StaticResource SearchMetroTextBox}" Width="200"                                           Margin="5"  Text=" TextBox With Search Button " />  4.     <TextBox Text=" TextBox with select all text on focus " Width="200" Margin="5"         metro:TextBoxHelper.SelectAllOnFocus="True" />  5.    <TextBox Text=" TextBox Watermark " Width="200" Margin="5"         metro:TextBoxHelper.Watermark="Type something" />

What is Prism?

Image
Prism is a framework for building loosely coupled, maintainable, and testable XAML applications in WPF, Windows 10 UWP, and Xamarin Forms.Prism provides an implementation of a collection of design patterns that are helpful in writing well-structured and maintainable XAML applications, including MVVM, dependency injection, commands, EventAggregator, and others. Prism's core functionality is a shared code base in a Portable Class Library targeting these platforms. Those things that need to be platform specific are implemented in the respective libraries for the target platform. Prism also provides great integration of these patterns with the target platform. Here is the video for creating Application using Prism in Wpf

what is ConcurrentDictionary?

ConcurrentDictionary is one of five collection classes introduced in .NET 4.0. It exists in System.Collections.Concurrent namespace.ConcurrentDictionary is thread-safe collection class to store key/value pairs. ConcurrentDictionary can be used with multiple threads concurrently. Without ConcurrentDictionary class, if we have to use Dictionary class with multiple threads, then we have to use locks to provides thread-safety which is always error-prone.ConcurrentDictionary provides you an easy option. It internally manages the locking gives you an easy interface to add/update items. ConcurrentDictionary provides different methods as compared to Dictionary class. We can use AddOrUpdate, GetOrAdd ,TryAdd, TryUpdate, TryRemove, and TryGetValue to do CRUD operations on ConcurrentDictionary.

What is the difference between Finalize() and Dispose() methods?

Dispose() is called when we want to realese an unmanaged resources of an object. finalize() also called for same but it doesn't assure object is garbage collected. The dispose() method is defined inside the interface IDisposable whereas, the method finalize() is defined inside the class object. The main difference between dispose() and finalize() is that the method  dispose() has to be explicitly invoked by the user whereas, the method  finalize() is invoked by the garbage collector, just before the object is destroyed.