Search Results

Search found 9 results on 1 pages for 'padu merloti'.

Page 1/1 | 1 

  • RelayCommand sender from ItemsControl item

    - by Padu Merloti
    I've been using MVVM's RelayCommand with success to bind actions to XAML, but I'm having a small problem with my ItemsControl. <ItemsControl ItemsSource="{Binding Devices}" > <ItemsControl.ItemTemplate> <DataTemplate> <Grid Width="100" Margin="4" > <Button Command="{Binding Path=SelectDeviceCommand}" > <Grid> <Image Source="img_small.png"></Image> <Image Source="{Binding Path=Logo}" /> </Grid> </Button> </Grid> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl> In my view model: public RelayCommand SelectDeviceCommand { get; set; } private ObservableCollection<Device> Devices; Devices = CreateListOfDevices(); private void InitializeCommands() { SelectDeviceCommand = new RelayCommand((s) => MessageBox.Show(s.ToString())); } How do I define my SelectDeviceCommand in my view model in order to receive object that is bound to that item? My SelectDeviceCommand is not even being called... (but that I guess is because I need to make my Device a mini-viewmodel and implement the SelectDeviceCommand in it, is that correct?)

    Read the article

  • How to TDD Asynchronous Events?

    - by Padu Merloti
    The fundamental question is how do I create a unit test that needs to call a method, wait for an event to happen on the tested class and then call another method (the one that we actually want to test)? Here's the scenario if you have time to read further: I'm developing an application that has to control a piece of hardware. In order to avoid dependency from hardware availability, when I create my object I specify that we are running in test mode. When that happens, the class that is being tested creates the appropriate driver hierarchy (in this case a thin mock layer of hardware drivers). Imagine that the class in question is an Elevator and I want to test the method that gives me the floor number that the elevator is. Here is how my fictitious test looks like right now: [TestMethod] public void TestGetCurrentFloor() { var elevator = new Elevator(Elevator.Environment.Offline); elevator.ElevatorArrivedOnFloor += TestElevatorArrived; elevator.GoToFloor(5); //Here's where I'm getting lost... I could block //until TestElevatorArrived gives me a signal, but //I'm not sure it's the best way int floor = elevator.GetCurrentFloor(); Assert.AreEqual(floor, 5); } Edit: Thanks for all the answers. This is how I ended up implementing it: [TestMethod] public void TestGetCurrentFloor() { var elevator = new Elevator(Elevator.Environment.Offline); elevator.ElevatorArrivedOnFloor += (s, e) => { Monitor.Pulse(this); }; lock (this) { elevator.GoToFloor(5); if (!Monitor.Wait(this, Timeout)) Assert.Fail("Elevator did not reach destination in time"); int floor = elevator.GetCurrentFloor(); Assert.AreEqual(floor, 5); } }

    Read the article

  • Intelligent serial port mocks with Moq

    - by Padu Merloti
    I have to write a lot of code that deals with serial ports. Usually there will be a device connected at the other end of the wire and I usually create my own mocks to simulate their behavior. I'm starting to look at Moq to help with my unit tests. It's pretty simple to use it when you need just a stub, but I want to know if it is possible and if yes how do I create a mock for a hardware device that responds differently according to what I want to test. A simple example: One of the devices I interface with receives a command (move to position x), gives back an ACK message and goes to a "moving" state until it reaches the ordered position. I want to create a test where I send the move command and then keep querying state until it reaches the final position. I want to create two versions of the mock for two different tests, one where I expect the device to reach the final position successfully and the other where it will fail. Too much to ask?

    Read the article

  • BeginInvoke on ObservableCollection not immediate.

    - by Padu Merloti
    In my code I subscribe to an event that happens on a different thread. Every time this event happens, I receive an string that is posted to the observable collection: Dispatcher currentDispatcher = Dispatcher.CurrentDispatcher; var SerialLog = new ObservableCollection<string>(); private void hitStation_RawCommandSent(object sender, StringEventArgs e) { string command = e.Value.Replace("\r\n", ""); Action dispatchAction = () => SerialLog.Add(command); currentDispatcher.BeginInvoke(dispatchAction, DispatcherPriority.Render); } The code below is in my view model (could be in the code behind, it doesn't matter in this case). When I call "hitstation.PrepareHit", the event above gets called a couple times, then I wait and call "hitStation.HitBall", and the event above gets called a couple more times. private void HitBall() { try { try { Mouse.OverrideCursor = Cursors.Wait; //prepare hit hitStation.PrepareHit(hitSpeed); Thread.Wait(1000); PlayWarning(); //hit hitStation.HitBall(hitSpeed); } catch (TimeoutException ex) { MessageBox.Show("Timeout hitting ball: " + ex.Message); } } finally { Mouse.OverrideCursor = null; } } The problem I'm having is that the ListBox that is bound to my SerialLog gets updated only when the HitBall method finishes. I was expecting seeing a bunch of updates from the PrepareHit, a pause and then a bunch more updates from the HitBall. I've tried a couple of DispatcherPriority arguments, but they don't seem to have any effect.

    Read the article

  • Does Adorner breaks MVVM?

    - by Padu Merloti
    I'm developing a WPF app using MVVM. Most of my views have only xaml markup and nothing (except default boilerplate) on code behind. All except one view that I use adorners to "blacken" the screen when I want to make the whole screen disabled. private void Window_Loaded(object sender, RoutedEventArgs e) { //todo: transfer to modelview contentAreaAdorner = AdornerLayer.GetAdornerLayer(contentArea); waitingAdorner = new WaitingAdorner(contentArea); } Is that ok? Or is there a better way to implement this in my viewmodel?

    Read the article

  • RectangleGeometry with relative dimensions... how?

    - by Padu Merloti
    I'm trying to replicate the nowadays so fashionable "reflex" effect on a controltemplate for buttons I'm creating. The basic idea is to create a rectangle with a gradient fill from white to transparent and then clip some of that semi-transparent rectangle with a rectanglegeometry. The problem is that I don't know how to define a relative rectangle geometry. I kind of worked around width by defining a large value (1000), but height is a problem. For example, it works good for buttons that have a 200 height, but doesn't do anything for smaller buttons. Any ideas? <Rectangle RadiusX="5" RadiusY="5" StrokeThickness="1" Stroke="Transparent"> <Rectangle.Fill> <LinearGradientBrush StartPoint="0,0" EndPoint="0,0.55"> <GradientStop Color="#66ffffff" Offset="0.0" /> <GradientStop Color="Transparent" Offset="1.0" /> </LinearGradientBrush> </Rectangle.Fill> <Rectangle.Clip> <RectangleGeometry Rect="0,0,1000,60" /> </Rectangle.Clip> </Rectangle>

    Read the article

  • Dealing with array of IntPtr

    - by Padu Merloti
    I think I'm close and I bet the solution is something stupid. I have a C++ native DLL where I define the following function: DllExport bool __stdcall Open(const char* filePath, int *numFrames, void** data); { //creates the list of arrays here... don't worry, lifetime is managed somewhere else //foreach item of the list: { BYTE* pByte = GetArray(i); //here's where my problem lives *(data + i * sizeofarray) = pByte; } *numFrames = total number of items in the list return true; } Basically, given a file path, this function creates a list of byte arrays (BYTE*) and should return a list of pointers via the data param. Each pointing to a different byte array. I want to pass an array of IntPtr from C# and be able to marshal each individual array in order. Here's the code I'm using: [DllImport("mydll.dll",EntryPoint = "Open")] private static extern bool MyOpen( string filePath, out int numFrames, out IntPtr[] ptr); internal static bool Open( string filePath, out int numFrames, out Bitmap[] images) { var ptrList = new IntPtr[512]; MyOpen(filePath, out numFrames, out ptrList); images = new Bitmap[numFrames]; var len = 100; //for sake of simplicity for (int i=0; i<numFrames;i++) { var buffer = new byte[len]; Marshal.Copy(ptrList[i], buffer, 0, len); images[i] = CreateBitmapFromBuffer(buffer, height, width); } return true; } Problem is in my C++ code. When I assign *(data + i * sizeofarray) = pByte; it corrupts the array of pointers... what am I doing wrong?

    Read the article

  • Display a WPF window inside another

    - by Padu Merloti
    Before pointing me to http://stackoverflow.com/questions/1287820/have-a-wpf-window-inside-another-wpf-window or telling me that MDI is soooo 1995, let me explain my application. I'm creating a MessageBanner window that works similar to the message banner we see in several sites nowadays (including SO) I want client code to call my message banner using four different modes: MessageBanner.Show(content); MessageBanner.Show(content, ownerWindow); MessageBanner.ShowModal(content); MessageBanner.ShowModal(content, ownerWindow); I believe you got the application. The thing is that when ownerWindow is displayed, I want to display my MessageBanner window inside the ownerWindow. Any ideas on how to do it?

    Read the article

1