I am trying to upgrade WinForms to Telerik Controls and when I am upgrading this
this.treeAccounting.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.TreeAccountingAfterSelect);
To this new RadControl Statement:
this.treeAccounting.SelectedNode += new Telerik.WinControls.UI.RadTreeViewEventArgs(this.TreeAccountingAfterSelect);
I get an error about best overloaded method match having invalid arguments for the TreeAccountingAfterSelect. Also it says cannot convert from 'method group' to 'Telerik.WinControls.UI.RadTreeNode'. Here is the function event for TreeAccountingAfterSelect.
private void TreeAccountingAfterSelect(object sender, Telerik.WinControls.UI.RadTreeViewEventArgs e)
{
string strSelectedNode = treeAccounting.SelectedNode.Text;
// Since the user can select any node (root, branch, leaf) of a tree in any order -
// cannot presume that they will select a root, then a leaf - so handle accordingly.
if (treeRootNames[(int)TreeNodes.TrialBalance] == strSelectedNode)
{
// Configure the Generator for doing a Trial Balance (detail) report
CrntReport = ReportTypes.TrialBalance;
CrntLocation = Locations.UNKNOWN;
// Based on default settings in the Report Property dialog (from App.Config) initialize
// screen controls.
lblCurrency.Visible = rptProperties.TBShowCurrencyCodes;
cboxCurrencyCode.Visible = rptProperties.TBShowCurrencyCodes;
this.Refresh();
// Setup the selections for the various parameters in the TrialBalance
// Parameters group.
SetupTBControls();
}
return;
}
I'm new to Telerik and I have tried different events and tried changing the parameter passed through the function and for some reason it isn't letting me use it like the WinForms. Can someone tell me where I am not understanding the change in WinForms to Telerik.
Looking at their documentation it seems that there is no SelectedNode event for a RadTreeView.
Instead you have
SelectedNodeChanged Occurs when selected node has been changed.
SelectedNodeChanging Occurs when the selected node is changing
And you don't use the RadTreeViewEventArgs to bind the event handler but a RadTreeViewEventHandler
So perhaps you need to write
this.treeAccounting.SelectedNodeChanged +=
new RadTreeViewEventHandler(this.TreeAccountingAfterSelect);
The syntax for delegate will allow also
this.treeAccounting.SelectedNodeChanged += this.TreeAccountingAfterSelect;
Related
I'm using Gong WPF to drag and drop a ListView with an ObservableCollection() as the ItemSource and the default behavior works great.
I recently added grouping to the listview and found that the default behaviors can't d&d between groups. I also need to override behavior so that the group is updated when dropping into a new group in the list.
So I implemented IDropBehavior and the two handlers and I can intercept the events as expected, but now the default d&d behavior of the automatic list move operations no longer works at all - within the same group or across groups.
Code is this:
public class RequestListModel : IDropTarget {
public void DragOver(IDropInfo dropInfo)
{
dropInfo.Effects = DragDropEffects.Move;
dropInfo.DropTargetAdorner = DropTargetAdorners.Insert;
//dropInfo.NotHandled = true;
}
public void Drop(IDropInfo dropInfo)
{
var item = dropInfo.TargetItem as HttpRequestData;
if (item == null) return;
var source = dropInfo.Data as HttpRequestData;
if (source == null) return;
if (source.Group != item.Group)
{
source.Group = item.Group;
source.RequestContent = source.ToRequestHttpHeader(true, true, true, StressTester.Options.SiteBaseUrl);
GroupRefresh();
}
//dropInfo.NotHandled = true;
}
}
Is it possible to override IDropTarget and still get the default behavior that automatically moves items, or is it now necessary to explicitly move the items in the collection manually? I was hoping the droptInfo.NotHandled switch might help but that seems to have no effect set either way...
--- updated
It's simple enough to do the collection updates manually since Gong conveniently provides the drop index. So it's easy to:
remove the source item
re-insert at the drop location
In the Drop() method above this works:
AppModel.Requests.Remove(source);
var idx = dropInfo.InsertIndex;
if (idx < AppModel.Requests.Count)
AppModel.Requests.Insert(dropInfo.InsertIndex, source);
else
AppModel.Requests.Add(source);
Easy as that is, it still seems like the default behavior (which appears to do roughly this) should still be available in some way without manually shifting items around.
I have followed the monogame wpf sample and the old XNA wpf sample to create a view in WPF with a loaded model through monogame (I'm also using mvvmlight but that shouldn't matter much I hope).
Everything else works except the contentManager I.e. Making a cube out of vertices is displayed fine with a local instance of GraphicsDevice
Depending on whether I use IntPtr.Zero or the actual window handle to create the instance of GraphicsDevice I get a different error and neither give many details so I don't know which I should persue...
When I use IntPtr.Zero
_services = new ServiceContainer();
_services.AddService(typeof(IGraphicsDeviceService), _graphicsDeviceService);
ContentManager content = new ContentManager(_services, "");
var model = content.Load<Model3D>("psp"); // At this line
I get an error about
"The type initializer for 'Microsoft.Xna.Framework.TitleContainer' threw an exception."
Inner Exception: The process has no package identity. (Exception from HRESULT: 0x80073D54)
But when I use the Actual WindowPointer I get this error
Managed Debugging Assistant 'FatalExecutionEngineError' has detected a problem in 'E:\Documents\Visual Studio 2013\Projects\XSITE2DEV\xSite2Dev\MvvmMonogameTest\bin\Debug\MvvmMonogameTest.vshost.exe'.
Additional information: The runtime has encountered a fatal error. The address of the error was at 0x71985144, on thread 0x5f38. The error code is 0xc0000005. This error may be a bug in the CLR or in the unsafe or non-verifiable portions of user code. Common sources of this bug include user marshaling errors for COM-interop or PInvoke, which may corrupt the stack.
In the GraphicsDeviceService creating the first instance of GraphicsDevice
I get my window pointer by using these methods
/// <summary>
/// Gets a reference to the singleton instance.
/// </summary>
public static GraphicsDeviceService AddRef(int width, int height)
{
var singletonInstance = SimpleIoc.Default.GetService(typeof(IGraphicsDeviceService)) as GraphicsDeviceService;
// Increment the "how many controls sharing the device" reference count.
if (Interlocked.Increment(ref _referenceCount) == 1)
{
// If this is the first control to start using the
// device, we must create the device.
singletonInstance.EnsureGraphicsDevice();
}
return singletonInstance;
}
private void EnsureGraphicsDevice()
{
if (_graphicsDevice != null)
return;
//CreateDevice(IntPtr.Zero, 1, 1);
CreateDevice(new WindowInteropHelper(Application.Current.MainWindow).Handle, 1, 1);
}
private void CreateDevice(IntPtr windowHandle, int width, int height)
{
_parameters = new PresentationParameters
{
BackBufferWidth = Math.Max(width, 1),
BackBufferHeight = Math.Max(height, 1),
BackBufferFormat = SurfaceFormat.Color,
DepthStencilFormat = DepthFormat.Depth24,
DeviceWindowHandle = windowHandle,
PresentationInterval = PresentInterval.Immediate,
IsFullScreen = false
};
_graphicsDevice = new GraphicsDevice(
GraphicsAdapter.DefaultAdapter,
GraphicsProfile.HiDef,
_parameters);
if (DeviceCreated != null)
DeviceCreated(this, EventArgs.Empty);
}
I feel like using the actual window pointer is the correct approach but the error has no further details so I can't go anywhere with it..
I came across a similar error while using an implementation as yours. For me, it occured because Game.Instance was null and if you look up the source code of GraphicsDevice at the MonoGame source, you will find that the constructor depends on that (at least in OpenGL).This link could be helpful:
https://github.com/mono/MonoGame/issues/2586
Basically, you have two options:
Bringing a Game in (e.g. inheriting from Game) will set Game.Instance in the constructor
Customizing the MonoGame Source to use your Handle
By the way I am not 100% sure that this is what is causing your error message.
I know that this post is old and I am quite likely too late but this may be helpful for anybody else who is experiencing this error.
We want to fire Events, with event names saved in SQL Server
In the SQL Server you'll find ApplicationExitRequestEvent
When we click the menu button, we'll get the string from the MenuItem
Type t = Type.GetType(SelectedMenu.View + "," + "AssemblyName");
var obj = Activator.CreateInstance(t);
if (t != null)
{
//Working firing Event with className
EventAggregator.GetEvent<ApplicationExitRequestEvent>().Publish(null);
//Generic?
EventAggregator.GetEvent<???>().Publish(null);
}
Ist it possible to do?
Working with PRISM and MVVM - WPF - .NET 4.0
if you look at the EventAggregator class, you'll see it's nothing more than a container Dictionary<Type, EventBase> and the GetEvent method. That's it, all the actual work is done in EventBase. In order to achieve what you want, you could modify the class (or make a copy and modify that), and add a method GetEvent( string typeString ) in which you convert the typeString to an actual Type (same way as in your code sample) and use that to fetch the event from the dictionary.
Got it, working fine now!
Pimped the Prism Library, to get the event by Type :-)
/// <summary>
/// Gets the single instance of the event managed by this EventAggregator.
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1004:GenericMethodsShouldProvideTypeParameter")]
public CompositePresentationEvent<object> GetEvent(Type type)
{
EventBase existingEvent = null;
events.TryGetValue(type, out existingEvent);
if(existingEvent != null)
return (CompositePresentationEvent<object>)existingEvent;
return null;
}
Thank you guys!
I asked this question in a similar post but there have been significant updates since then, but still no results so I will try to re-ask the question with the updated information.
Basically I have a pivot view with 4 pivot items. If I create the scenario where I hit the windows key then rapidly press the back key my application will reopen without reconstructing (this is the expected outcome). The functionality of the application is there. I can press application bar buttons etc.
What doesn't work is the pivot items are frozen. If I was on Pivot item A and I press the start and back button quickly I come back to Pivot Item A. If I try to switch Pivot Items, the screen does not update, its "frozen" on Pivot Item A BUT the functionality of Pivot Item B is there. (I know this because the application bar Icons for Pivot Item B are now showing).
I have read many articles on proper tombstoning scenarios and how to approach this problem. My data IS being tombstoned correctly, and upon reactivation the tombstoned data works. No objects are null so I don't have any exceptions being thrown at me.
I check to see if I need to reload the Main ViewModel (I don't need to in this case so the UI elements being created initially are not being re created).
What does fix the problem however is if the application is reconstructed. Lets say I go to the marketplace from my app, let it finish loading and press back, My application will be refreshed and working fine since it properly deactivated and reconstructed istelf. I don't rely on constructors doing all the work so I am not missing any key elements not being set when they aren't fired in the windows/back button scenario.
Does anyone have any idea why my screen would not be updating?
constructor/loaded event/on navigated to event
public MainPage()
{
InitializeComponent();
this.Loaded += new RoutedEventHandler(MainPage_Loaded);
}
private void MainPage_Loaded(object sender, RoutedEventArgs e)
{
if (App.firstTimeLoading == true)
{
App.firstTimeLoading = false;
}
BuildApplicationBar();
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
this.DataContext = App.ViewModel;
App.viewIdentifier = StringResource.MainPageView;
if (!App.ViewModel.IsDataLoaded)
{
App.ViewModel.LoadData();
String bookTitle;
App.Parser.appBookInfoDict.TryGetValue(CPlayerInventoryKeys.kInventoryKeyTitleShortTitle, out bookTitle);
PivotBackground.Title = bookTitle.ToUpper();
CreatePivotItems();
}
if (App.playerController.chapterPlayer.Source == null)
App.restoreStateClass.RestoreState();
//applies the proper background image
if (App.isDarkTheme)
{
BitmapImage bitmapImage = new BitmapImage(new Uri(StringResource.PanoramaBlackImage, UriKind.Relative));
BackgroundImage.ImageSource = bitmapImage;
BackgroundImage.Opacity = .85;
}
else
{
BitmapImage bitmapImage = new BitmapImage(new Uri(StringResource.PanoramaWhiteImage, UriKind.Relative));
BackgroundImage.ImageSource = bitmapImage;
BackgroundImage.Opacity = .5;
}
if (App.firstTimeLoading == false && PivotBackground.SelectedItem != SuggestedPivotItem)
BuildApplicationBar();
else if (PivotBackground.SelectedItem == SuggestedPivotItem)
{
BuildMarketPlaceApplicationBar();
}
base.OnNavigatedTo(e);
}
I found the answer. Since I had a media element open (play/paused) and I was implementing the "non tombstoned" method of hitting windows key and back button very quickly, the media element source was corrupt. Even though I reset this source, apparently it can be ignored and not function properly. All I had to do was add a line of code to the Application Deactivated handler.
private void Application_Deactivated(object sender, DeactivatedEventArgs e)
{
App.MainAudioPlayer.Source = null; //(only showing line added)
}
The behavior you are describing seems to be solely related to the way you are manipulating data internally and constructing your layout. I tested this both in the emulator and on a couple of physical devices, both producing normal output (even when bound to a view model).
Try creating a new Pivot-based application (without all your data - just using the default template) and see if the problem persists. Also worth mentioning - are you testing on a device or in the emulator?
Are you using transitions from the toolkit?
Are they defined in XAML?
If so that could be the issue. There's a bug which is fixed in the next version.
The solution for now is to remove the transitions or define them in code.
I'm relatively new to TDD, and still trying to learn to apply some of the concepts. Here's my situation.
I've got a WinForm with a DataGridView. I'm trying to write a test for the routine to be called by a button click that will perform some operations on the selected rows of the grid.
So I will be passing in the DataGridViewSelectedRowCollection object (i.e, the dgv.SelectedRows property at the time the button is clicked).
The DataGridViewSelectedRowCollection object has no constructor, so the only way I can figure to create it is to put together a DataGridView in my test project, then select some rows and pass in the SelectedRows property. But clearly, I don't want to re-create the whole form there.
So I do a DataGridView dgv = new DataGridView(), and gin up a BindingList (actually a SortableBindingList) just like the grid is bound to in the real application. The test list has 3 rows in it. And I do a dgv.DataSource = myList.
Now, at that point in the real application, the grid view is bound. If I look at dgv.Rows.Count, it's equal to the number of rows in the list. However, in my test, setting the DataSource property to the list still results in zero rows in the grid.
I'm thinking there's something missing in the creation of the gridview that normally gets done when it's added to the control list of the form. It probably initializes the handler for the OnDataSourceChanged event or something, and that isn't being done in my test code, but I'm really at a loss as to how to fix it, again, without re-creating a whole form object in my test fixture.
Here's the relavant code form my test method:
DataGridView residueGrid = new DataGridView();
List<Employee> baseListToGrid = new List<Employee>();
SortableBindingList<Employee> listToGrid = new SortableBindingList<Employee>(baseListToGrid);
residueGrid.DataSource = listToGrid;
for (int ix = 1; ix < 4; ix++)
{
listToGrid.Add(ObjectMother.GetEmployee(ix));
}
Assert.AreEqual(3, listToGrid.Count, "SortableBindingList does not have correct count");
Assert.AreEqual(3, residueGrid.Rows.Count, "DataGrid is not bound to list");
Thanks for any help you can give me.
DataGridView residueGrid = new DataGridView();
List<Employee> baseListToGrid = new List<Employee>();
SortableBindingList<Employee> listToGrid = new SortableBindingList<Employee>(baseListToGrid);
// residueGrid.DataSource = listToGrid; <-- move this line...
for (int ix = 1; ix < 4; ix++)
{
listToGrid.Add(ObjectMother.GetEmployee(ix));
}
// residueGrid.DataSource = listToGrid; <-- ...to here!
Assert.AreEqual(3, listToGrid.Count, "SortableBindingList does not have correct count");
Assert.AreEqual(3, residueGrid.Rows.Count, "DataGrid is not bound to list");
A useful structure for writing test is the following:
public void MyTest()
{
// Arrange
// Act
// Assert
}
In this case, Arrange would be instantiating all the objects, and filling the list. Act is where you set the data source of the gridview, and Assert is where you check that everything went OK. I usually write out those three comment lines each time I start writing a test.
Well, I solved the problem, and pretty much confirmed that it is something being done in the initialization of the control when added to the form that makes the DataSource binding work.
It suddenly dawned on me that that the "target" created by the MS testing framework is a private accessor to the Form itself. So I changed the line
DataGridView residueGrid = new DataGridView();
in the above code to, instead of creating a new DGV object, just reference the one on the target form:
DataGridView residueGrid = target.residueGrid;
That change made everything work as expected.