How do I bind a callback function to a DataTemplate inside a HeaderTemplate in WinUI3?
After reading various answers it appears the DataContext inside a HeaderTemplate is different
than throughout the rest of the XAML file.
The callback function is defined in the AM2BasePageViewModel class, which is called in the AM2BasePage constructor as such:
AM2BasePage::AM2BasePage()
{
m_am2BasePageViewModel = winrt::make<bionet::implementation::AM2BasePageViewModel>();
InitializeComponent();
}
Trying out various things, the relevant part in my XAML file now looks like this:
<muxc:NavigationView x:Name="NavigationView"
SelectionChanged="NavigationView_SelectionChanged"
AlwaysShowHeader="True"
Canvas.ZIndex="0"
Header="s"
IsBackButtonVisible="Collapsed"
BackRequested="NavigationView_BackRequested"
Background="Transparent"
IsSettingsVisible="True"
Margin="0">
<NavigationView.HeaderTemplate>
<DataTemplate x:DataType="local:AM2BasePage" >
<CommandBar x:Name ="AM2BaseCommandPanel" HorizontalAlignment="Left" HorizontalContentAlignment="Left">
<CommandBar.PrimaryCommands>
<AppBarButton x:Name="AM2BaseCommandPanelLoad" Icon="Document" Label="Attach Camera"/>
<AppBarSeparator />
<AppBarButton x:Name="AM2BaseCommandPanelRunSimulation" Icon="Play" Label="Like" Click="{x:Bind AM2BaseViewModel.RunSimulation_click, Mode=OneWay}"/>
<AppBarSeparator />
</CommandBar.PrimaryCommands>
</CommandBar>
</DataTemplate>
</NavigationView.HeaderTemplate>
<muxc:NavigationView.MenuItems>
<muxc:NavigationViewItem Content="Home" Icon="Home" ToolTipService.ToolTip="Home"/>
<muxc:NavigationViewItem
x:Uid="AM2BasePage_NavigationViewItem_Values"
Icon="Page2" ToolTipService.ToolTip="Collections">
<muxc:NavigationViewItem.MenuItems>
<muxc:NavigationViewItem
Tag="bionet.AM2BasePageInitialValues"
x:Uid="AM2BasePage_NavigationViewItem_Values_InitialValues"
ToolTipService.ToolTip="Bookshelf"/>
<muxc:NavigationViewItem
Tag="bionet.AM2BasePageParameters"
x:Uid="AM2BasePage_NavigationViewItem_Values_Parameters"
ToolTipService.ToolTip="Mail"/>
</muxc:NavigationViewItem.MenuItems>
</muxc:NavigationViewItem>
</muxc:NavigationView.MenuItems>
<Frame x:Name="ContentFrame">
</Frame>
</muxc:NavigationView>
The relevant part is
Click="{x:Bind AM2BaseViewModel.RunSimulation_click, Mode=OneWay}".
This compiles but immediately crashes my program upon clicking the command bar with
Exception thrown at 0x00007FFCDA4C4F69 (KernelBase.dll) in bionet.exe: WinRT originate error - 0x80004002 : 'No such interface supported'.
Exception thrown at 0x00007FFCDA4C4F69 in bionet.exe: Microsoft C++ exception: winrt::hresult_no_interface at memory location 0x0000009728D5A198.
Exception thrown at 0x00007FFCDA4C4F69 in bionet.exe: Microsoft C++ exception: [rethrow] at memory location 0x0000000000000000.
Exception thrown at 0x00007FF6EBE9A039 in bionet.exe: 0xC0000005: Access violation reading location 0x0000000000000000.
I assume I do the callback function binding wrong. How can I call the callback function without the program crashing?
Edit: The AM2BasePageView header looks as such:
#pragma once
#include "pch.h"
#include "AM2BasePageViewModel.g.h"
namespace winrt::bionet::implementation
{
struct AM2BasePageViewModel : AM2BasePageViewModelT<AM2BasePageViewModel>
{
public:
AM2BasePageViewModel();
void RunSimulation_click();
private:
winrt::event<Microsoft::UI::Xaml::Data::PropertyChangedEventHandler> m_propertyChanged;
};
}
namespace winrt::bionet::factory_implementation
{
struct AM2BasePageViewModel : AM2BasePageViewModelT<AM2BasePageViewModel, implementation::AM2BasePageViewModel>
{
};
}
The problem looks you missed RoutedEventHandler parameter for Click method. In general, I don't recommend declare click routed event handler in view model, because it will pass current button instance into view model that make view and viewmodel are highly coupled.
You could bind AppBarButton Command property. please research C++/WinRT XAML command handling tutorial.
Related
Im currently trying to track a PageEvent within a ASHX Handler. My code basically looks like this:
public class GetProductPdf : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
if (!Tracker.IsActive)
{
Tracker.Initialize();
Tracker.StartTracking();
}
//Track PageEvent here...
}
public bool IsReusable
{
get
{
return false;
}
}
}
The Tracker is always inactive and Tracker.Current == null. On method call "Tracker.StartTracking();" the following Exception is thrown:
[InvalidOperationException: Tracker.Current is not initialized]
Sitecore.Analytics.Pipelines.StartAnalytics.StartTracking.Process(PipelineArgs args) +317
(Object , Object[] ) +83
Sitecore.Pipelines.CorePipeline.Run(PipelineArgs args) +445
Project.Web.Handler.PdfCreation.GetProductPdf.ProcessRequest(HttpContext context) in d:\Project\Website\Handler\PdfCreation\GetProductPdf.ashx.cs:69
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +913
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +165
I tried all possible solutions suggested here.
When doing the same in a mvc controller the Tracker is active and Tracker.Current != null.
Does anyone has an idea, what could cause this or are there any other suggestions for a solution?
Thanks in advance.
I am not certain that your Ashx Handler can be executed within the necessary Sitecore Context so that Tacker.Current will not be valid nor can be started via Tracker.StartTracking(). Someone might be able to confirm but I have another solution you can try which works for me.
As nice as it would be for the Ashx Handler to register the Event for you, instead you can fire a JavaScript function on the link to the file. So that when the link is clicked the JavaScript makes a web request to a MVC Controller and the controller registers the event for you.
I have implemented this myself using WebApi Controllers. Data Attributes were on the a tag, JavaScript posted those attributes to the controller, the controller used those attributes to determine which Event to register and the description to use on the Event.
<asp:HyperLink runat="server" data-goalid="{08030449-A811-428B-95F0-59FCD42B8DEB}" data-goaldescription="Product 0112 brochure">
[System.Web.Mvc.HttpPost]
public JsonResult RegisterGoal(string goalId, string goalDescription)
{
Item eventItem = Sitecore.Context.Database.GetItem(goalId);
var goal = new PageEventItem(eventItem);
var eventData = Tracker.Current.PreviousPage.Register(goal);
eventData.Data = goal["Description"] + " " + goalDescription;
Tracker.Current.Interaction.AcceptModifications();
return Json(new PageEventRequestResult()
{
Success = true,
Message = "Successfully registered goal",
});
}
It works really well. The only downside is having to add it to the various links that lead to the files you want to track.
I wrote a blog about tracking various interactions on a site and registering Sitecore Events / Goals you might want to look at, scroll down to the 'Storing custom data in xDB' section.
I have a web service which uses a C++/CLI DLL that I created to perform certain operations. Now, the C++/CLI DLL calls a function from a third party DLL which throws an exception ONLY when it is used via the web service. If it is used in a standalone application, the process is smooth. I create a mini dump any time the exception occurs, which can be either an access violation or stack overflow. From looking at the call stack (seen below), I notice that the exception is thrown by a std::_Init_locks::operator= function. I don't completely understand its responsibility or why the exception occurs when it is called, hence my plea for assistance. So my question is, why do I only get an exception when this DLL is being called via a web service and why does it occur at this point?
(Project specifications: .NET 4.0 for web service and C++/CLI DLL)
Thanks in advance.
Stack trace:
Child-SP RetAddr Call Site
00000000`019f3a38 00000000`1894e332 frsdk_9_0_0!std::_Init_locks::operator=+0x3cf
00000000`019f3a50 00000000`18945d09 frsdk_9_0_0!FRsdk::CaptureDeviceBody::operator=+0x6152
00000000`019f3a90 00000000`1894620d frsdk_9_0_0!FRsdk::Box::endy+0xc55b9
00000000`01a38610 00000000`18946380 frsdk_9_0_0!FRsdk::Box::endy+0xc5abd
00000000`01a387b0 00000000`18946567 frsdk_9_0_0!FRsdk::Box::endy+0xc5c30
00000000`01a38820 00000000`188818e3 frsdk_9_0_0!FRsdk::Box::endy+0xc5e17
00000000`01a38860 00000000`1888e0a9 frsdk_9_0_0!FRsdk::Box::endy+0x1193
00000000`01a38950 00000000`188a02b4 frsdk_9_0_0!FRsdk::Box::endy+0xd959
00000000`01a38b00 00000000`1884e6a5 frsdk_9_0_0!FRsdk::Box::endy+0x1fb64
00000000`01a38c70 00000000`1882fb34 frsdk_9_0_0!FRsdk::CaptureDeviceBody::gainRange+0x4e255
00000000`01a38d80 00000000`187af3ab frsdk_9_0_0!FRsdk::CaptureDeviceBody::gainRange+0x2f6e4
00000000`01a3a280 00000000`180fc62a frsdk_9_0_0!FRsdk::Enrollment::Processor::process+0x174b
00000000`01a3a3c0 00000000`180f1227 BioEngine!BioAlgos::Encode+0x24a
00000000`01a3a6d0 00000000`180f1dab BioEngine!BioAlgos::EncodeAndWriteTemplate+0x27
00000000`01a3a740 00000000`18027365 BioEngine!BioAlgos::EnrollSubject+0x30b
00000000`01a3ab70 00000000`180aecb0 BioEngine!FRE::Enroll+0x185
00000000`01a3ad40 00000000`1811be4b BioEngine!RecogProcessor::Enroll+0x290
00000000`01a3aec0 000007fe`96c7dfe9 BioEngine!RecogProcessor_Enroll+0x16b
00000000`01a3b350 000007fe`96c7db2f 0x000007fe`96c7dfe9
00000000`01a3b430 000007fe`96c78d05 0x000007fe`96c7db2f
00000000`01a3b510 000007fe`96c77698 0x000007fe`96c78d05
00000000`01a3bb30 000007fe`96c76117 0x000007fe`96c77698
00000000`01a3c0b0 000007fe`96c7269d 0x000007fe`96c76117
00000000`01a3c6f0 000007fe`96c7cc1d 0x000007fe`96c7269d
00000000`01a3d800 000007fe`96c7c017 0x000007fe`96c7cc1d
00000000`01a3dc50 000007fe`96c7bd6e 0x000007fe`96c7c017
00000000`01a3dcd0 000007fe`96d79599 0x000007fe`96c7bd6e
00000000`01a3dd60 000007fe`f2161663 0x000007fe`96d79599
00000000`01a3dde0 000007fe`f215db45 System_ServiceModel_ni+0x631663
00000000`01a3dfc0 000007fe`f215d330 System_ServiceModel_ni+0x62db45
00000000`01a3e370 000007fe`f215c9cb System_ServiceModel_ni+0x62d330
00000000`01a3e420 000007fe`f215b3de System_ServiceModel_ni+0x62c9cb
00000000`01a3e600 000007fe`f215a8f7 System_ServiceModel_ni+0x62b3de
00000000`01a3e6c0 000007fe`f2158ca3 System_ServiceModel_ni+0x62a8f7
00000000`01a3eaa0 000007fe`f21587cb System_ServiceModel_ni+0x628ca3
00000000`01a3eb20 000007fe`f19ed1a2 System_ServiceModel_ni+0x6287cb
00000000`01a3eb80 000007fe`f19e7aaa System_ServiceModel_Internals_ni+0x4d1a2
00000000`01a3ebd0 000007fe`f19ed3d1 System_ServiceModel_Internals_ni+0x47aaa
00000000`01a3ec80 000007fe`f19eccdc System_ServiceModel_Internals_ni+0x4d3d1
00000000`01a3ecd0 000007fe`f19ec8ae System_ServiceModel_Internals_ni+0x4ccdc
00000000`01a3ee40 000007fe`f2185232 System_ServiceModel_Internals_ni+0x4c8ae
00000000`01a3eeb0 000007fe`f2184b9f System_ServiceModel_ni+0x655232
00000000`01a3ef10 000007fe`f2184a0a System_ServiceModel_ni+0x654b9f
00000000`01a3ef90 000007fe`f19eb3d5 System_ServiceModel_ni+0x654a0a
00000000`01a3efc0 000007fe`f19ed1a2 System_ServiceModel_Internals_ni+0x4b3d5
00000000`01a3f040 000007fe`f19e7aaa System_ServiceModel_Internals_ni+0x4d1a2
00000000`01a3f090 000007fe`f218426b System_ServiceModel_Internals_ni+0x47aaa
00000000`01a3f140 000007fe`f19ed1a2 System_ServiceModel_ni+0x65426b
00000000`01a3f1b0 000007fe`ed1feece System_ServiceModel_Internals_ni+0x4d1a2
00000000`01a3f200 000007fe`ed1bb917 System_Web_ni+0xb8eece
00000000`01a3f2f0 000007fe`ed1f1ef0 System_Web_ni+0xb4b917
00000000`01a3f330 000007fe`ed0baac4 System_Web_ni+0xb81ef0
00000000`01a3f390 000007fe`f62bac23 System_Web_ni+0xa4aac4
00000000`01a3f3f0 000007fe`f62d49ec clr!UM2MThunk_WrapperHelper+0x43
00000000`01a3f430 000007fe`f62c94ae clr!UM2MThunk_Wrapper+0x54
00000000`01a3f480 000007fe`f62d4975 clr!Thread::DoADCallBack+0x12e
00000000`01a3f650 000007fe`f62babcd clr!UM2MDoADCallBack+0x91
00000000`01a3f6d0 000007fe`eb400326 clr!UMThunkStub+0x26d
00000000`01a3f760 000007fe`eb3f1bfe webengine4!W3_MGD_HANDLER::DoWork+0x293
00000000`01a3f7c0 000007fe`ef31ba3c webengine4!RequestDoWork+0x34e
00000000`01a3f860 000007fe`ef3146a4 iiscore!NOTIFICATION_CONTEXT::RequestDoWork+0x314
00000000`01a3f8a0 000007fe`ef31a775 iiscore!NOTIFICATION_CONTEXT::CallModulesInternal+0x174
00000000`01a3f990 000007fe`ef315a03 iiscore!NOTIFICATION_CONTEXT::CallModules+0x25
00000000`01a3f9e0 000007fe`ef311741 iiscore!W3_CONTEXT::DoWork+0x34d
00000000`01a3fd00 000007fe`f8e710b2 iiscore!W3_MAIN_CONTEXT::OnIoCompletion+0x81
00000000`01a3fd30 000007fe`f8e7109c w3dt!UL_NATIVE_REQUEST::DoWork+0x22b
00000000`01a3fd90 000007fe`f95e1fba w3dt!OverlappedCompletionRoutine+0x1c
00000000`01a3fdc0 000007fe`f95e2024 w3tp!THREAD_POOL_DATA::ThreadPoolThread+0x7a
00000000`01a3fe10 000007fe`f95e20a1 w3tp!THREAD_POOL_DATA::ThreadPoolThread+0x34
00000000`01a3fe40 00000000`76e55a4d w3tp!THREAD_MANAGER::ThreadManagerThread+0x61
00000000`01a3fe70 00000000`7708b831 kernel32!BaseThreadInitThunk+0xd
00000000`01a3fea0 00000000`00000000 ntdll!RtlUserThreadStart+0x1d
Is it possible to debug JavaScript when using DukeScript?
I've tried adding FirebugLite
<script type='text/javascript' src='http://getfirebug.com/releases/lite/1.2/firebug-lite-compressed.js'></script>
It loads and that's awesome but it has no visibility of the $root model.
Also I don't know if it's possible to add breakpoints.
Partly, one can include FirebugLite. See for example here.
One problem I've found is that Firebug loads but has no visibility of the model, $root returns undefined.
I've tried to work around this problem by creating a Javascript resource MyResource.js under main/resouces
MyResource = {
loadFirebug: function(){
if (!document.getElementById('FirebugLite')){
E = document['createElement' + 'NS'] && document.documentElement.namespaceURI;
E = E ? document['createElement' + 'NS'](E, 'script') : document['createElement']('script');
E['setAttribute']('id', 'FirebugLite');
E['setAttribute']('src', 'https://getfirebug.com/' + 'firebug-lite.js' + '#startOpened');
E['setAttribute']('FirebugLite', '4');(document['getElementsByTagName']('head')[0] || document['getElementsByTagName']('body')[0]).appendChild(E);
E = new Image;E['setAttribute']('src', 'https://getfirebug.com/' + '#startOpened');
}
},
someProperty: "someProperty"
};
Then we create a correpsponding Java class in order to load the resource
#JavaScriptResource("MyResource.js")
public class MyResource {
#net.java.html.js.JavaScriptBody(
args = {}, body =
"MyResource.loadFirebug();"
)
public static native void loadFireBug();
}
Now in the onPageLoad() Java method we can invoke the JavaScript method that loads FirebugLite
/**
* Called when the page is ready.
*/
public static void onPageLoad() throws Exception {
d = new Data();
d.setMessage("Hello World from HTML and Java!");
d.applyBindings();
MyResource.loadFireBug();
}
Now when Firebug starts, it has at least a scope of its enclosing resource.
We still can't add breakpoints because the resource doesn't appear under the files. Perhaps DukeScript experts can suggest a better way of handling this.
Note 1: you can use load Bootstrap simply by including it into the the page with the script tag. See here
Note 2: Unfortunately FireBug Lite seems to have some problems with Bootstrap, beyond version 1.2. See here
Note 3: Here are a couple of ways on how to access a DukeScript model from the javascript context
I am trying to create an event handler for sitecore .
I have done following steps.
create a dll named "TestEventHandlers" and
add its reference in bin folder of my website.
Add following line in my web.config events --> event node: <handler type="TestEventHandlers.EventHandler , TestEventHandlers" method="OnItemSaved"/>
But i am getting following error:
Could not resolve type name:
TestEventHandlers.EventHandler, TestEventHandlers.EventHandler
(method: Sitecore.Configuration.Factory.CreateType(XmlNode configNode, String[] parameters, Boolean assert)).
I am confused about assembly name in type attribute of handler.
The assembly-qualified name of a type consists of the type name, including its namespace, followed by a comma, followed by the display name of the assembly. > MSDN
The assembly-qualified name for you class might look like this:
TestEventHandlers.EventHandler, TestEventHandlers
Assuming that your dll (assembly) is named TestEventHandlers and the class you wrote is called EventHandler within the TestEventHandlers namespace. In other words, you have this code in your TestEventHandlers dll and that dll is in the bin directory of your Sitecore web site.
namespace TestEventHandlers
{
public class EventHandler
{
public void OnItemSaved(object sender, EventArgs args)
{
}
}
}
Assuming
dll name as- TestEventHandlers.dll , &
class description as - namespace TestEventHandlers.Events{ public class EventHandler{...}} your handler entry shuld be <
handler type="TestEventHandlers.Events.EventHandler , TestEventHandlers" method="OnItemSaved"/>
I create a simple silverlight 4.0 application used to read the excel file data in the share point 2010 server. I try to use the "Excel Web Services" but I get an error here when calling the GetRangeA1 method:
An unhandled exception of type 'System.ServiceModel.Dispatcher.NetDispatcherFaultException' occurred in mscorlib.dll
Additional information: The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://schemas.microsoft.com/office/excel/server/webservices:GetRangeA1Response. The InnerException message was 'Error in line 1 position 361. Element 'http://schemas.microsoft.com/office/excel/server/webservices:anyType' contains data from a type that maps to the name 'http://schemas.microsoft.com/office/excel/server/webservices:ArrayOfAnyType'. The deserializer has no knowledge of any type that maps to this name. Consider using a DataContractResolver or add the type corresponding to 'ArrayOfAnyType' to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding it to the list of known types passed to DataContractSerializer.'. Please see InnerException for more details.
the source code is like:
namespace SampleApplication
{
class Program
{
static void Main(string[] args)
{
ExcelServiceSoapClient xlservice = new ExcelServiceSoapClient();
xlservice.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
Status[] outStatus;
string targetWorkbookPath = "http://phc/Shared%20Documents/sample.xlsx";
try
{
// Call open workbook, and point to the trusted location of the workbook to open.
string sessionId = xlservice.OpenWorkbook(targetWorkbookPath, "en-US", "en-US", out outStatus);
Console.WriteLine("sessionID : {0}", sessionId);
//1. works fines.
object res = xlservice.GetCellA1(sessionId, "CER by Feature", "B1", true, out outStatus);
//2. exception
xlservice.GetRangeA1(sessionId, "CER by Feature", "H19:H21", true, out outStatus);
// Close workbook. This also closes session.
xlservice.CloseWorkbook(sessionId);
}
catch (SoapException e)
{
Console.WriteLine("SOAP Exception Message: {0}", e.Message);
}
}
}
}
I am totally new to the silverlight and sharepoint developping, I search around but didn't get any luck, just found another post here, any one could help me?
This appears to be an oustanding issue, but two workarounds I found so far:
1) Requiring a change in App.config.
http://social.technet.microsoft.com/Forums/en-US/sharepoint2010programming/thread/ab2a08d5-2e91-4dc1-bd80-6fc29b5f14eb
2) Indicating to rebuild service reference with svcutil instead of using Add Service Reference:
http://social.msdn.microsoft.com/Forums/en-GB/sharepointexcel/thread/2fd36e6b-5fa7-47a4-9d79-b11493d18107