I am using Chart.JS in a Blazor project and seem to have run into a limitation, there seems to be no obvious way to pass a callback, for example a callback for the tick to modify the tick text displayed:
Scales = new
{
y = new
{
ticks = new
{
color = "white",
callback = How do I pass a calback here??
},
}
},
Any ideas on how to accomplish this in Blazor?
Related
I'm trying to do auto redirect when session timeout using WebForms. I searched but found the codes that sets the predefined limit. but they never reset when we press key or move pointer etc. I reset the session timeout using ajax by calling ajax on each mouse move and keypress but this effecting the other script in terms of performance making it slower etc. I have tried this clear and clean code for this job also applied some ajax but never succeeded. https://code.msdn.microsoft.com/Auto-redirect-to-login-e1782b2f
Here is my service that get the session expire time on each mouse move or keypress.
[WebMethod (EnableSession=true)]
public static string GETExpireTime()
{
DateTime date = DateTime.Now;
int sessionTimeout = HttpContext.Current.Session.Timeout;
DateTime dateExpress = date.AddMinutes(sessionTimeout);
return dateExpress.ToString("u", DateTimeFormatInfo.InvariantInfo).Replace("Z", "");
}
Here is how I'm resetting it in jquery.
$(document).ready(function () {
$(document).keyup(function () {
var data = {};
setCookie("express", generalAjax(data, 'GETExpireTime').d);
});
$('*').mouseenter(function () {
var data = {};
setCookie("express", generalAjax(data, 'GETExpireTime').d);
});
});
Please help me if there is another way to do this perfectly as all codes set predefined time and force logout after that interval But I need to reset at mouse move or keypress. Thanks
Why do you use ajax for every keypress or mouse enter?
You can use interval function in jQuery to check is timeout or not. And if it time out, do every thing you need.
For start interval you just set a variable of start session time and an other variable duration.
I would it helps you.
As this solution can be done with JavaScript only. So I came up with my own code. That is based on counter. Counter is reset on keyup or mouse movement. also event is cleared and being registered back.
<script>
var delay = 10000;
var sTimeoutMinutes = "<%=Session.Timeout %>";
var sTimeoutSeconds = 60 * sTimeoutMinutes;
var loops = sTimeoutSeconds / (delay / 1000);
var globalCounter = 0
var timeOutInterval = setInterval(processSessionTimeout, delay);
$(document).ready(function () {
$(document).keyup(function () {
globalCounter = 0;
clearInterval(timeOutInterval);
timeOutInterval = setInterval(processSessionTimeout, delay);
});
$('*').mouseenter(function () {
globalCounter = 0;
clearInterval(timeOutInterval);
timeOutInterval = setInterval(processSessionTimeout, delay);
});
});
function processSessionTimeout() {
globalCounter += 1;
if (globalCounter >= loops) {
clearInterval(timeOutInterval);
Redirect();
}
}
function Redirect() {
window.location.replace("/Pages/Account/SignIn.aspx?session=Expired");
}
</script>
I've scoured this site and numerous other resources for trying to track this down.
I have a console application that I am trying to get have a system tray icon for.
That part works.
What I cannot actually get to work is adding a menu to it when I right click. I really just need an exit button that will shut it down.
My entire class is fairly small so I will include it. I have initialized this object in my main method and thats pretty much all I need since I drive this from the constructor. I've found resource that indicated I would not need a click event but I've tried both so Im not exactly sure.
I've tried patching this together from other resources but everyone seems to have a slightly different problem or I'm missing something.
Thanks for taking a look.
namespace PvsMessageLogger
{
public class SystemTray
{
private readonly string _systemDisplayName;
private readonly NotifyIcon _systemTray;
public SystemTray(string systemDisplayName)
{
_systemTray = new NotifyIcon();
_systemDisplayName = systemDisplayName;
InitializeSystemTray();
}
private void InitializeSystemTray()
{
_systemTray.Icon = new Icon(SystemIcons.Application, 40, 40);
_systemTray.Visible = true;
_systemTray.BalloonTipTitle = _systemDisplayName;
_systemTray.BalloonTipText = _systemDisplayName + " is running in the background";
MenuItem[] menuList = {new MenuItem("Exit", (s, e) => Application.Exit()) };
ContextMenu clickMenu = new ContextMenu(menuList);
_systemTray.ContextMenu = clickMenu;
_systemTray.ShowBalloonTip(1000);
}
}
}
Just found the answer in another thread, you must add Application.Run() after you create the icon.
You can find more details on Roman's answer.
so after more than a week of trying to solve it on my own I officially give up and turn to your help. Basically, it should not be so complicated so I have no idea why it does not work. I have a WPF app which contains a Main Window called surprise surpise...: Main_Window.
That window contain a user control called 'pageTransitionControl' that change its content according to what the client want to see. the 'pageTransitionControl' is there to support multiple animations and so on... Anyway, among all of the user controls, i have a preety havy uc called ucBanks. before it shows, the ucBanks load a lot of data, manipulating it and display it on a very beautiful and smart charts. the problem is it takes some time to load it, approximately 6-7 seconds so i need the UI to show 'Loading' animation during that time (another user control called 'ucSpinner').
I'm Trying to load the ucBanks on a different thread to avoid freezing the application and it works great: the ucSpinner is showed immidiatlly and the ucBanks is loading on the background but when i change the content of the 'pageTransitionControl' i get this error:
"The calling thread cannot access this object because a different thread owns it".
I think i tried basically everything but i must missing somthing or doing somthing wrong.
This is where it all start, the btn_click event that load ucBanks:
ShowSpinner();
Thread.Sleep(100);
Thread newThread = new Thread(new ThreadStart(LoadUc));
newThread.SetApartmentState(ApartmentState.STA);
newThread.IsBackground = true;
newThread.Start();
This is the ShowSpinner method:
private void ShowSpinner()
{
ucSpinner.Opacity = 1;
}
and this is the LoadUc method:
private void LoadUc()
{
ucOsh ucOshx = new ucOsh();
Utils.LoadUc(ucOshx, null, PageTransitions.PageTransitionType.GrowAndFade, true, this, null, true);
}
With the LoadUc i called static class called 'Utils' holding the 'LoadUc' method:
public static void LoadUc(System.Windows.Controls.UserControl ucParent, System.Windows.Controls.UserControl ucChild, PageTransitions.PageTransitionType tranType, bool removeChildrens = true, System.Windows.Window w = null, List<Plist.Plist> lst = null, bool hideMenu = false)
{
MainWindow win = null;
if (w != null) { win = (MainWindow)w; }
else { win = (MainWindow)System.Windows.Window.GetWindow(ucChild); }
win.Dispatcher.Invoke(
System.Windows.Threading.DispatcherPriority.ContextIdle, (System.Action)delegate
{
win.pageTransitionControl.TransitionType = tranType;
win.pageTransitionControl.PARAMS = lst;
win.pageTransitionControl.Tag = ucParent.ToString();
win.pageTransitionControl.pages.Push(ucParent);
win.pageTransitionControl.Content = ucParent; ----------->>>>This is where i get the error!!!
});
}
I understand that the main window is locked inside another thread but i cant see any other option to load it without freezing the entire app.
Does anyone have a suloution to my problem? SA :-) ?
What I have tried:
i tried working with background-worker, i chaned all of the settings of the dispatcher, loaded the user control inside and outside the threads...
I've got a chart that I've created and formatted (no data yet) in the public form, right after the initcomponent().
the series is populated upon event triggered (camera firing a imageavailable event), at that point I gather some pixels and fill the series with data.
This should work fine but I get a "cross thread error", saying that my chart was created in a different thread.
here's what my code looks like:
public Form1()
{
InitializeComponent();
CreateStarProfileChart();
.../...
here's my function:
private void CreateStarProfileChart()
{
// Y axis init
StarProfile.ChartAreas.Add("Area1");
StarProfile.ChartAreas["Area1"].AxisY.Title = "Pixel Values";
StarProfile.ChartAreas["Area1"].AxisY.Minimum = 0;
StarProfile.ChartAreas["Area1"].AxisY.Maximum = 4096;
StarProfile.ChartAreas["Area1"].AxisY.Interval = 500;
StarProfile.ChartAreas["Area1"].AxisY.MajorGrid.Enabled = true;
StarProfile.ChartAreas["Area1"].AxisY.MajorGrid.LineColor = Color.Gray;
StarProfile.ChartAreas["Area1"].AxisY.MajorGrid.LineDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Dash;
StarProfile.ChartAreas["Area1"].AxisY.MinorTickMark.Enabled = true;
// X axis init
StarProfile.ChartAreas["Area1"].AxisX.Title = "Pixels Accross Centroid";
StarProfile.ChartAreas["Area1"].AxisX.MajorGrid.Enabled = true;
StarProfile.ChartAreas["Area1"].AxisX.MajorGrid.LineColor = Color.Gray;
StarProfile.ChartAreas["Area1"].AxisX.MajorGrid.LineDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Dash;
StarProfile.ChartAreas["Area1"].AxisX.MinorTickMark.Enabled = true;
// Series init
StarProfile.Series.Add("StarProfile");
StarProfile.Series["StarProfile"].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
StarProfile.Series["StarProfile"].BorderWidth = 2;
StarProfile.Series["StarProfile"].Color = Color.Black;
}
and finally, here's the code in the event that's triggered every few seconds:
// Clear Chart and Re-init Chart
StarProfile.Series["StarProfile"].Points.Clear();
StarProfile.ChartAreas["Area1"].AxisX.Minimum = -BoxDim;
StarProfile.ChartAreas["Area1"].AxisX.Maximum = BoxDim;
StarProfile.ChartAreas["Area1"].AxisX.Interval = 5;
for (int sl = -BoxDim; sl <= BoxDim; sl++)
{
// Add points to chart
StarProfile.Series["StarProfile"].Points.AddXY(sl, PixelMap[CoordX + sl, CoordY]);
../.. // some more maths following but that's all that's related to the chart itself...
any idea how I could do what I want to do?
thanks
Steve
Put your update code into a method like this (it probably already is, but you haven't posted it...):
void RefreshChart()
{
// Clear Chart and Re-init Chart
StarProfile.Series["StarProfile"].Points.Clear();
StarProfile.ChartAreas["Area1"].AxisX.Minimum = -BoxDim;
...
}
Then, from your code (assumedly running in a background thread) which is calling RefreshChart(), call it like this, using an anonymous delegate:
Invoke((Action)(() => RefreshChart()));
This should eliminate your error, by marshalling the function call back to the main UI thread.
(Note that in this particular case, you can simplify the call further using method group syntax:)
Invoke((Action)RefreshChart);
I want to make hovering button in my game. Because when my cursor touch the button it will go to another screen immediately. I don't like this so much. I use xna 4.0 with visual studio 2010 to make this project. (use kinect without wpf)
How to use timer in this case ? Please help me
if (Hand.contian(Button) && holdtime == targetHoldtime)
{
}
You have to manage time by yourself based in elapsed time per frame:
ft = GameTime.Elapsed.TotalSeconds; // Xna
ft= 1/30f; // 30fps
And can be done in similar way to this:
class Button {
public float Duration = 1; // One second
public Rectangle Bounds; // Button boundaries
public float Progress { get{ return Elapsed/Duration; } }
float Elapsed = 0;
public void Update(float ft) {
if (Bounds.Contains( HandPosition ))
{
if (Elapsed<Duration) {
Elapsed += ft;
if (Elapsed>Duration) {
Elapsed = Duration;
OnClick();
}
}
} else {
Elapsed = 0;
}
}
}
I would first suggest that you look through the SDK documentation and the built in KinectInteraction controls. They may provide you with what you are looking for. Most notably SDK 1.7 removed that "HoverDwell" button in favor of a "press" action, which is a more natural interaction in a gesture system. You may want to look at using that motion instead.
If you truly desire a "click on hover" type action, you can look at the code in SDK 1.6 for an example. Several examples are available online at the Kinect for Windows CodePlex repository. The specific control example you are looking for is in the "BasicInteraction-WPF" project, and is called HoverDwellButton.
The "button" is actually a ContentControl which means you can place any content in there to make it a button. It can be a simple image, or a complex Grid. It has all the hooks to fire events when the timer on your hover goes off.
There is a decent amount of complexity in this control, which is what makes it work for a wide range of applications. At the core of the interaction is a simple DispatcherTimer.
private void OnPreviewHandEnter(object sender, HandInputEventArgs args)
{
if (this.trackedHandHovers.FirstOrDefault(t => t.Hand.Equals(args.Hand)) == null)
{
// additional logic removed for answer sanity
var timer = new HandHoverTimer(DispatcherPriority.Normal, this.Dispatcher);
timer.Hand = args.Hand;
timer.Interval = TimeSpan.FromMilliseconds(Settings.Default.SelectionTime);
timer.Tick += (o, s) => { this.InvokeHoverClick(args.Hand); };
this.trackedHandHovers.Add(timer);
timer.Start();
}
args.Handled = true;
}
Notice that the Tick event is calling InvokeHoverClick, which (in part) reads as follows:
public void InvokeHoverClick(HandPosition hand)
{
// additional logic removed for answer sanity
var t = new DispatcherTimer();
t.Interval = TimeSpan.FromSeconds(0.6);
t.Tick += (o, s) =>
{
t.Stop();
var clickArgs = new HandInputEventArgs(HoverClickEvent, this, hand);
this.RaiseEvent(clickArgs);
this.IsSelected = false;
};
t.Start();
}
This now fires an event after a set amount of time. This event can be capture and acted upon to your liking.
Again, I first recommend looking at the newer interactions in SDK 1.7. If you still want a timed hover click action, check out the links above. I used the HoverDwellButton to great effect in several different areas.