Custom RepositoryItemProgressBar - c#

Hello i want to create my own RepositoryItemProgressBar. So that enduser can choose value in the ProgressBar. Normaly the ProgressBar only shows the value but is not editable.
My Problem is starting to write own RepositoryItem. I cant find the Item in the Grid Designer to bind it on column.
I tried following:
[UserRepositoryItem("RegisterBxProgressBar")]
public class RepositoryItemBxProgressBar : RepositoryItemProgressBar
{
internal static string EditorName = "BxProgressBar";
static RepositoryItemBxProgressBar()
{
Register();
}
/// <summary>
/// Registriert die Komponente
/// </summary>
public static void Register()
{
EditorRegistrationInfo.Default.Editors.Add(new EditorClassInfo(EditorName, typeof(ProgressBarControl),
typeof(RepositoryItemBxProgressBar), typeof(ProgressBarViewInfo), new ProgressBarPainter(), true,
EditImageIndexes.ProgressBarControl, typeof(DevExpress.Accessibility.ProgressBarAccessible)));
}
}
Maybe someone can help me how to start with a new RepositoryItem?
regards

It is not quite clear to me why do not use the TrackBarControl which is specially designed to provide capability to edit value via dragging thumb.
Anyway you should start from the Custom Editors help article when creating custom editors.
Yet another way is demonstrated in the following example:
How to create TrackBarControl with ProgressBar instead of a track line

Related

Windows Forms - ErrorProvider overlapping icons

I'm using a custom icon in my ErrorProvider with
ErrorProvider.BlinkStyle = ErrorBlinkStyle.NeverBlink
I've got a problem with overlapping icons using code that is similar to this one:
public partial class TestForm : Form
{
private ErrorProvider _errorProvider1;
private ErrorProvider _errorProvider2;
private CheckBox _control1;
private CheckBox _control2;
//...
private void ValidateAll()
{
_errorProvider1.Clear();
_errorProvider2.Clear();
_errorProvider1.SetError(_control1, string.Empty);
_errorProvider2.SetError(_control2, string.Empty);
if(Validate(_control1.Checked))
{
_errorProvider1.SetError(_control1, "Error1");
}
if(Validate(_control2.Checked))
{
_errorProvider2.SetError(_control2, "Error2");
}
}
//...
}
I'm interacting with _control1 while _control2 has some error (is Checked), thus _errorProvider2 has some error set. Everytime method ValidateAll is called it will correctly set _errorProvider1 for _control1 but _control2 _errorProvider2 will keep drawing extra icons without erasing old ones.
Starting view
After 'clicking' _control1 multiple times
When interacting with _control2, _errorProvider2 will go back to normal, but _control1's _errorProvider1 will do the same until it is 'clicked'.
After 'clicking' _control2
Please note that underlying Control doesn't affect it; it doesn't have to be CheckBox.
What I tried:
Using only one ErrorProvider per Form/Control,
Focusing each Control before setting ErrorProvider,
Not clearing ErrorProviders
Any help is much appreciated, thanks!

mvvmlight wpf how to raise frame source property wpf c#

(See Solution below)
Struggling learning MVVMLight and WPF. Happy to get page navigation with a frame with 3 buttons and also get the CanExecute RelayCommand functionality working for the buttons.
However, when I change pages with the Back and Forward button from the frame, the frame navigation buttons seem to not raise the propertychanged for the Frame Source Property FrameURI in the viewmodel. In the RelayCommand execute I'm looking at the FrameURI property to determine button command can execute. I'm thinking that I need to raisepropertychange of FrameURI property in the viewmodel after a Frame FWD or BACK button press. It looks like I can do that in a Navigated or LoadCompleted EVENT from the NavigationService Class. Is this the best way to go about this? Maybe there's an easier way?
PROPER BEHAVIOR HERE:
NOT WORKING CORRECTLY HERE when the frame BACK button is pressed. The page changes (good), but the button Middle canexecute didn't update correctly. See property and relay commands further below.
MVVMINPCPROPERTY snippet
public const string FrameUriPropertyName = "FrameUri";
private Uri _frameUri;
/// <summary>
/// Sets and gets the FrameUri property.
/// Changes to that property's value raise the PropertyChanged event.
/// </summary>
public Uri FrameUri
{
get
{
return _frameUri;
}
set
{
Set(FrameUriPropertyName, ref _frameUri, value);
}
}
XAML for Frame
<Frame x:Name="MainFrameDS" Source="{Binding FrameUri}" HorizontalAlignment="Left" Height="211" Margin="109,88,0,0" VerticalAlignment="Top" Width="258"/>
RelayCommand example
private RelayCommand _changeToLastPage;
/// <summary>
/// Gets the ChangeToLastPage.
/// </summary>
public RelayCommand ChangeToLastPage
{
get
{
return _changeToLastPage
?? (_changeToLastPage = new RelayCommand(
() =>
{
FrameUri = ViewModelLocator.LastPageUri;
},
() => FrameUri != ViewModelLocator.LastPageUri));
}
}
I have the source code on github and using Win7 and VS2017 Community. I also have other issues w/ the program and opened issues on github. Any help is appreciated.
My goal is to have a few basic MVVMLight program 'templates' that I can pull from and share them w/ other learners like me... Thanks.
Solution
Add Mode=twoway to the binding per #steve-teece.
Did some DEBUG.writeline (Break point suggestion per #Michael-Randall) to the output window and found out that the URI for the page was different depending on if it referred back to the viewmodellocater.IntroPageUri or called by the frame FWD or BACK button.
The two URI results were:
/IntroPage.xaml OR IntroPage.xaml
My assumption was that the 'non-fore slash' version didn't equal the version with a '/'.
I'm not sure of the best way to solve this so I converted the URI's to strings and compared them w/ the string Contains method in a boolean method.
I replaced the follow line:
FrameUri != ViewModelLocator.IntroPageUri
It was replaced with a method call:
CheckUri(FrameUri, ViewModelLocator.IntroPageUri)
And, the CheckUri method:
private Boolean CheckUri(Uri _frameUriToCheck, Uri _vmUri)
{
string StringUriToCheck = _frameUriToCheck.ToString();
string StringUriVM = _vmUri.ToString();
System.Diagnostics.Debug.WriteLine(StringUriToCheck, "StringUriToCheck");
System.Diagnostics.Debug.WriteLine(StringUriVM, "StringUriVM");
if (StringUriVM.Contains(StringUriToCheck))
{ return false; }
else
{ return true; }
}
That worked! If someone has a better way to solve it, I'm all ears.
Thanks all for the feedback!
try changing the XAML to
<Frame x:Name="MainFrameDS" Source="{Binding FrameUri, Mode=TwoWay}" HorizontalAlignment="Left" Height="211" Margin="109,88,0,0" VerticalAlignment="Top" Width="258"/>
Firstly, make sure you are referencing
GalaSoft.MvvmLight.CommandWpf;
and not
using GalaSoft.MvvmLight.Command;
If your CanExcute is not getting evaluated you might need to manually raise the change via RaiseCanExecuteChanged
public Uri FrameUri
{
get
{
return _frameUri;
}
set
{
if(Set(FrameUriPropertyName, ref _frameUri, value))
{
// assuming this is the command you are having trouble with
// this will force the command to reevaluate CanExecute
ChangeToLastPage.RaiseCanExecuteChanged();
}
}
}
Update
Omg i didnt even notice this
public const string FrameUriPropertyName = "FrameUri";
you need to at least be setting this properly
Set(() => FrameUri, ref _frameUri, value);

Data Validation of Text written in TextBox, MVVM C#

I making an app, where I like writte some bytes into textbox. I like to validate if real HEX code is written into textbox or not and remind user if not.
I never made this in MVVM and XAML. How to do it? I find several tutorial on web, but problem is that I like to write 64 bytes. I have 64 textboxes pull together in one array.
One of the textbox:
<TextBox Text="{Binding TB[4], UpdateSourceTrigger=PropertyChanged}" Grid.Column="0" Grid.Row="0" Style="{StaticResource byteTextBoxStyle}"/>
and array variable:
private string[] _tb = new string[64];
public string[] TB
{
get
{ return _tb; }
set
{
_tb = value;
NotifyPropertyChanged("TB");
}
}
Goal is that red textblock is under of all textboxes and write a red (Something like that).
I can do it later when button is pressed - pull together array in to one string and check with regex is something is not OK. But I want this in real time, when user put-in text and right away recognite if is OK or not.
Please for help, because I am new in MVVM and WPF thing. If any question please ask. Thanks!
I have done something similar in the past using System.Windows.Interactivity.dll
https://www.nuget.org/packages/System.Windows.Interactivity.WPF/
All it does is terminate the key down event if a non hex value is keyed in.
{
/// <summary>
/// Provides functionality to allow users to type only letters [0-9 A-F a-f].
/// </summary>
public class HexEditTextBox : TriggerAction<DependencyObject>
{
protected override void Invoke(object parameter)
{
var textBox = this.AssociatedObject as TextBox;
if (textBox != null) textBox.PreviewKeyDown += HandlePreviewKeyDownEvent;
}
/// <summary>
/// Checks whether the input is a valid key for a Hex number.
/// Sets the 'Handled' Property as True if the input is invalid, so that further actions will not be performed for this Action.
/// </summary>
/// <param name="sender"></param>
/// <param name="e">KeyEventArgs instance</param>
private void HandlePreviewKeyDownEvent(object sender, KeyEventArgs e)
{
var acceptedKeys = new List<Key>()
{
Key.D0, Key.D1, Key.D2, Key.D3,Key.D4,Key.D5,Key.D6,Key.D7,Key.D8,Key.D9,
Key.A,Key.B,Key.C,Key.D,Key.E,Key.F,
Key.Tab,Key.Back,Key.Delete,Key.Left,Key.Right,Key.Up,Key.Down,Key.Enter,Key.Home,Key.End,
Key.NumPad0,Key.NumPad1,Key.NumPad2,Key.NumPad3,Key.NumPad4,Key.NumPad5,Key.NumPad6,Key.NumPad7,Key.NumPad8,Key.NumPad9
};
e.Handled = !acceptedKeys.Contains(e.Key);
}
}
}
You should be able to insert your validation here.

How to change the label of shared App bar in windows phone 8.1

Im developing an windows phone 8.1 app. I have used shared app bar across the pages. At some point of time, I need to change the label or the icon of the global app bar. Is this possible?
your thoughts will be helpful.
BottomAppBar at WP8.1 is CommandBar, there you will find PrimaryCommands property, in which you probably have AppBarButtons. If you want to change for example a Label (Icon or anything else), you should be able to do it like this:
// change the label of the first button
((BottomAppBar as CommandBar).PrimaryCommands[0] as AppBarButton).Label = "New Label";
If you want to change AppBarButton's parameters often, to make it easier, you can write a simple extension method:
/// <summary>
/// Get AppBarButton of AppBar - extension method
/// </summary>
/// <param name="index">index of target AppBarButton</param>
/// <returns>AppBarButton of desired index</returns>
public static AppBarButton PButton(this AppBar appBar, int index) { return (appBar as CommandBar).PrimaryCommands[index] as AppBarButton; }
Of course it's the same as above, but makes little easier to use:
BottomAppBar.PButton(0).Label = "New label";
If you store your app bar in Resources than you can access it through the following code:
var commandBar = Application.Current.Resources["YouResourceKeyForAppBar"] as AppBar;
Now you have a reference to it and you can modify items inside it. If you implemented SharedApp in another way, please edit your question and tell more information about it.
Perhaps I can suggest an alternate solution thanks to the 8.1 libraries in the Windows.UI.ViewManagement namespace namely the StatusBar and the ApplicationView's Title
It won't help out this situation, but might make things simpler for another who is looking at this post.
var titleName = "TITLE";
var statusBar = Windows.UI.ViewManagement.StatusBar.GetForCurrentView();
statusBar.ProgressIndicator.Text = titleName;
var applicationView = Windows.UI.ViewManagement.ApplicationView.GetForCurrentView();
applicationView.Title = titleName;
Then to show and hide, control with:
await statusBar.ProgressIndicator.ShowAsync();
await statusBar.ProgressIndicator.HideAsync();
Unfortunately, the only thing you'll be able to set up here is Title. I don't think you can set a custom Style to the StatusBar.
public MainPage()
{
this.InitializeComponent();
Loaded += MainPage_Loaded;
}
void MainPage_Loaded(object sender, RoutedEventArgs e)
{
CommandBar bottomCommandBar = this.BottomAppBar as CommandBar;
AppBarButton appbarButton_0 = bottomCommandBar.PrimaryCommands[0] as AppBarButton;
appbarButton_0.Label = "settings";
appbarButton_0.Icon = new SymbolIcon(Symbol.Setting);
}

How do you get the index of a column by the column name in an IList?

I apologize if this happens to be an easy question, but I'm new to coding. I've been banging my head against a wall with this problem for several days now on and off and have done numerous internet searches, but I keep coming up empty handed.
I have captured data from a database view into an IList. Because the data comes from a view and might (potentially) change the order of how columns appear should changes ever need to be made (columns added, etc), I want to programmatically pull the column's index from the IList via the column name.
This is easy enough to do with a gridview since it has a nice "HeaderRow" property that allows me to write a bit of code to loop through any row and pull the headerRow name, compare it to the name I'm looking for and then pull an incremented count number when I find it, and Voila!, I then have the index.
The problem is, I'm trying to avoid having to copy data from a list that was already copied from the entity framework that was copied from the database itself into another container (gridview) in order to have to manipulate it. It just seems like it's getting needlessly complex involving a gridview.
So, if anyone can tell me if there's a useful property of the IList class that I can use to acquire the column index # via the column name, please let me know and many thanks!
Edit:
In response to nvoigt's comment "An IList does not know anything about columns."
I'm sure it must have some idea, because when I step through the code and look at the first row data in the IList, it has the column names there ("AppAnswer", etc). All I want is some way to look through them and determine (by property or by code) what index that column name sits at. See photo for clarification.
I've had to link it here since my rep isn't high enough to post photos: https://www.dropbox.com/s/2xg3nduhqnzbl8n/ILisst.JPG
Also, this is the code that captures the data from the view and puts it into the list:
IList<View_AppQnA_All> list1 = useful.GetQuestionAnswerListForJobPosition(1);
public IList<View_AppQnA_All> GetQuestionAnswerListForJobPosition(int jobID)
{
IList<View_AppQnA_All> QuestionAnswerList = new List<View_AppQnA_All>();
IQueryable<View_AppQnA_All> view = Repository.Current.ObjectContext.
View_AppQnA_All.Where(Q => Q.AppQuestionForJobPosition == jobID);
QuestionAnswerList = view.ToList<View_AppQnA_All>();
return QuestionAnswerList;
}
#region Imports
using System;
using System.Drawing;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DataAccess;
#endregion
namespace AOJobApplication
{
class Repository
{
#region Declarations
private static Repository m_instance;
private static AOApplicationContext CWEntities;
// Lock synchronization object
//private static object syncLock = new object();
private static readonly object syncLock = new object();
#endregion
#region Properties
/// <summary>
/// Returns the one and only Repository
/// </summary>
public static Repository Current
{
get
{
if (m_instance == null)
{
lock (syncLock)
{
if (m_instance == null)
{
m_instance = new Repository();
}
}
}
return m_instance;
}
}
#endregion
/// <summary>
/// Object context to get entity objects application void
/// </summary>
public AOApplicationContext ObjectContext
{
get
{
if (CWEntities != null)
{
return CWEntities;
}
else
{
CWEntities = new AOApplicationContext();
return CWEntities;
}
}
}
}
}
The object you store in your list has properties, modeled after your view. Properties in a class don't have any order. They are just properties, they exist next to each other. You can order them in any way you like, the Visual Studio debugger seems to order them by name.
Those classes are generated, not dynamically built on the fly. If your view changes drastically (I guess by more than just field order), you will have to generate them again. This means recompile.

Categories

Resources